diff --git a/core/Makefile.dep b/core/Makefile.dep index 8ff0bd9..ee49ce6 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -323,6 +323,7 @@ log.o: ../../pikotools/textstream/types.h htmlfilter.h log.o: ../templates/htmltextstream.h ../core/textstream.h misc.h log.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h log.o: session.h user.h plugindata.h rebus.h mount.h ../templates/locale.h +log.o: timezones.h timezone.h misc.o: misc.h item.h ../../pikotools/space/space.h misc.o: ../../pikotools/date/date.h requesttypes.h misc.o: ../../pikotools/textstream/textstream.h diff --git a/core/app.cpp b/core/app.cpp index 1e9c5bd..a864bcc 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -652,8 +652,10 @@ void App::SetSubdomain() void App::LogAccess() { - log << log1 - << cur.request->start_date << ' ' + log << log1; + log.PrintDate(cur.request->start_date, config.log_time_zone_id); + + log << ' ' << cur.request->env_remote_addr << ' ' << cur.request->env_request_method << ' ' << cur.request->env_http_host diff --git a/core/config.cpp b/core/config.cpp index e77d026..d9a5057 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -112,6 +112,7 @@ void Config::AssignValues(bool stdout_is_closed) log_level = Int(L"log_level", 1); log_request = Int(L"log_request", 1); log_save_each_line = Bool(L"log_save_each_line", false); + log_time_zone_id = Size(L"log_time_zone_id", 34); log_stdout = Bool(L"log_stdout", false); log_db_query = Bool(L"log_db_query", false); log_plugin_call = Bool(L"log_plugin_call", false); diff --git a/core/config.h b/core/config.h index 9ab6023..1f567e1 100755 --- a/core/config.h +++ b/core/config.h @@ -65,6 +65,12 @@ public: // default: false bool log_save_each_line; + // time zone identifier used in log messages + // this affects only the first line of logs (where there is IP address, request method etc) + // see time_zone_default_id below for more info + // default: 34 (Coordinated Universal Time UTC+00:00) + size_t log_time_zone_id; + // logging db queries // default: false bool log_db_query; diff --git a/core/log.cpp b/core/log.cpp index ac889c4..2d66545 100755 --- a/core/log.cpp +++ b/core/log.cpp @@ -11,6 +11,7 @@ #include #include #include "utf8/utf8.h" +#include "timezones.h" Log::Log() @@ -22,6 +23,7 @@ Log::Log() lines = 0; max_lines = 5000; log_file_open = false; + time_zones = 0; } @@ -31,6 +33,14 @@ Log::~Log() } + +void Log::SetTimeZones(TimeZones * ptime_zones) +{ + time_zones = ptime_zones; +} + + + int Log::LogLevel() { return log_level; @@ -61,6 +71,29 @@ void Log::OpenFile() } +void Log::PrintDate(const PT::Date & date, size_t time_zone_id) +{ + if( time_zones ) + { + TimeZone * tz = time_zones->GetZone(time_zone_id); + + if( tz ) + { + PT::Date local_date = tz->ToLocal(date); + log << local_date; + } + else + { + (*this) << date << " UTC"; // unknown time zone identifier + } + } + else + { + (*this) << date << " UTC"; // time_zones object was not set + } +} + + Log & Log::operator<<(const void * s) { diff --git a/core/log.h b/core/log.h index 5d0cadd..7f6833b 100755 --- a/core/log.h +++ b/core/log.h @@ -20,6 +20,9 @@ #include "textstream/textstream.h" +class TimeZones; + + class Log { @@ -28,6 +31,7 @@ public: Log(); ~Log(); + void SetTimeZones(TimeZones * ptime_zones); void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests); Log & operator<<(const void * s); @@ -47,6 +51,8 @@ public: Log & operator<<(LogManipulators m); Log & operator<<(const PT::Date & date); + void PrintDate(const PT::Date & date, size_t time_zone_id); + template Log & operator<<(const PT::TextStreamBase & buf); @@ -67,6 +73,9 @@ public: private: + // time zones for printing the time in the log file + TimeZones * time_zones; + // buffer for the log TextStream buffer; diff --git a/main/Makefile.dep b/main/Makefile.dep index 4ec32c4..0c2e228 100755 --- a/main/Makefile.dep +++ b/main/Makefile.dep @@ -55,4 +55,4 @@ main.o: ../core/sessionmanager.h ../core/compress.h ../core/postparser.h main.o: ../core/httpsimpleparser.h ../core/plugin.h ../core/pluginmsg.h main.o: ../core/cookieparser.h ../core/postmultiparser.h main.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h -main.o: ../core/plugin.h +main.o: ../core/plugin.h ../core/version.h diff --git a/main/main.cpp b/main/main.cpp index 3e110bc..53eaf96 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -17,6 +17,7 @@ #include "core/slog.h" #include "core/app.h" #include "core/plugin.h" +#include "core/version.h" Log log; @@ -72,6 +73,22 @@ void CloseDescriptors() } +void LogInfo(LogManipulators log_level, const char * msg, bool put_version, const char * msg2) +{ + log << log_level; + log.PrintDate(PT::Date(std::time(0)), app.config.log_time_zone_id); + log << ' ' << msg; + + if( put_version ) + { + log << ' ' << WINIX_VER_MAJOR + << '.' << WINIX_VER_MINOR + << '.' << WINIX_VER_REVISION; + } + + log << ' ' << msg2 << logend; +} + int main(int argv, char ** argc) @@ -99,12 +116,14 @@ int main(int argv, char ** argc) if( app.config.demonize && !app.Demonize() ) return 4; + log.SetTimeZones(&app.system.time_zones); + log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file, app.config.log_stdout, app.config.log_request); nlog.Init(app.config.log_level, true, app.config.log_notify_file, false, 1); - log << log3 << "-- preparing to start winix --" << logend; + LogInfo(log3, "booting Winix", true, ""); if( !app.InitFCGI() ) return 5; @@ -124,13 +143,12 @@ int main(int argv, char ** argc) if( !app.Init() ) return 1; - log << log1 << PT::Date(std::time(0)) << " winix started" << logend; - app.StartThreads(); // now we have more threads, we should use Lock() and Unlock() // saving all starting logs app.Lock(); + LogInfo(log1, "Winix", true, "started"); log << logsave; app.Unlock(); @@ -146,7 +164,7 @@ int main(int argv, char ** argc) app.WaitForThreads(); // now all others threads are terminated - log << log1 << PT::Date(std::time(0)) << " winix stopped" << logend << logsave; + LogInfo(log1, "Winix", true, "stopped"); return 0; }