added: to config: log_time_zone_id (size_t) identifier
this is the time zone identifier used in log messages git-svn-id: svn://ttmath.org/publicrep/winix/trunk@882 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
0c6ddc2218
commit
9174555ff8
|
@ -323,6 +323,7 @@ log.o: ../../pikotools/textstream/types.h htmlfilter.h
|
||||||
log.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
|
log.o: ../templates/htmltextstream.h ../core/textstream.h misc.h
|
||||||
log.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.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: 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: misc.h item.h ../../pikotools/space/space.h
|
||||||
misc.o: ../../pikotools/date/date.h requesttypes.h
|
misc.o: ../../pikotools/date/date.h requesttypes.h
|
||||||
misc.o: ../../pikotools/textstream/textstream.h
|
misc.o: ../../pikotools/textstream/textstream.h
|
||||||
|
|
|
@ -652,8 +652,10 @@ void App::SetSubdomain()
|
||||||
|
|
||||||
void App::LogAccess()
|
void App::LogAccess()
|
||||||
{
|
{
|
||||||
log << log1
|
log << log1;
|
||||||
<< cur.request->start_date << ' '
|
log.PrintDate(cur.request->start_date, config.log_time_zone_id);
|
||||||
|
|
||||||
|
log << ' '
|
||||||
<< cur.request->env_remote_addr << ' '
|
<< cur.request->env_remote_addr << ' '
|
||||||
<< cur.request->env_request_method << ' '
|
<< cur.request->env_request_method << ' '
|
||||||
<< cur.request->env_http_host
|
<< cur.request->env_http_host
|
||||||
|
|
|
@ -112,6 +112,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||||
log_level = Int(L"log_level", 1);
|
log_level = Int(L"log_level", 1);
|
||||||
log_request = Int(L"log_request", 1);
|
log_request = Int(L"log_request", 1);
|
||||||
log_save_each_line = Bool(L"log_save_each_line", false);
|
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_stdout = Bool(L"log_stdout", false);
|
||||||
log_db_query = Bool(L"log_db_query", false);
|
log_db_query = Bool(L"log_db_query", false);
|
||||||
log_plugin_call = Bool(L"log_plugin_call", false);
|
log_plugin_call = Bool(L"log_plugin_call", false);
|
||||||
|
|
|
@ -65,6 +65,12 @@ public:
|
||||||
// default: false
|
// default: false
|
||||||
bool log_save_each_line;
|
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
|
// logging db queries
|
||||||
// default: false
|
// default: false
|
||||||
bool log_db_query;
|
bool log_db_query;
|
||||||
|
|
33
core/log.cpp
33
core/log.cpp
|
@ -11,6 +11,7 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "utf8/utf8.h"
|
#include "utf8/utf8.h"
|
||||||
|
#include "timezones.h"
|
||||||
|
|
||||||
|
|
||||||
Log::Log()
|
Log::Log()
|
||||||
|
@ -22,6 +23,7 @@ Log::Log()
|
||||||
lines = 0;
|
lines = 0;
|
||||||
max_lines = 5000;
|
max_lines = 5000;
|
||||||
log_file_open = false;
|
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()
|
int Log::LogLevel()
|
||||||
{
|
{
|
||||||
return log_level;
|
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)
|
Log & Log::operator<<(const void * s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#include "textstream/textstream.h"
|
#include "textstream/textstream.h"
|
||||||
|
|
||||||
|
|
||||||
|
class TimeZones;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
|
@ -28,6 +31,7 @@ public:
|
||||||
Log();
|
Log();
|
||||||
~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);
|
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);
|
Log & operator<<(const void * s);
|
||||||
|
@ -47,6 +51,8 @@ public:
|
||||||
Log & operator<<(LogManipulators m);
|
Log & operator<<(LogManipulators m);
|
||||||
Log & operator<<(const PT::Date & date);
|
Log & operator<<(const PT::Date & date);
|
||||||
|
|
||||||
|
void PrintDate(const PT::Date & date, size_t time_zone_id);
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
Log & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
Log & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
||||||
|
|
||||||
|
@ -67,6 +73,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// time zones for printing the time in the log file
|
||||||
|
TimeZones * time_zones;
|
||||||
|
|
||||||
// buffer for the log
|
// buffer for the log
|
||||||
TextStream<std::wstring> buffer;
|
TextStream<std::wstring> buffer;
|
||||||
|
|
||||||
|
|
|
@ -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/httpsimpleparser.h ../core/plugin.h ../core/pluginmsg.h
|
||||||
main.o: ../core/cookieparser.h ../core/postmultiparser.h
|
main.o: ../core/cookieparser.h ../core/postmultiparser.h
|
||||||
main.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
|
main.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
|
||||||
main.o: ../core/plugin.h
|
main.o: ../core/plugin.h ../core/version.h
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "core/slog.h"
|
#include "core/slog.h"
|
||||||
#include "core/app.h"
|
#include "core/app.h"
|
||||||
#include "core/plugin.h"
|
#include "core/plugin.h"
|
||||||
|
#include "core/version.h"
|
||||||
|
|
||||||
|
|
||||||
Log log;
|
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)
|
int main(int argv, char ** argc)
|
||||||
|
@ -99,12 +116,14 @@ int main(int argv, char ** argc)
|
||||||
if( app.config.demonize && !app.Demonize() )
|
if( app.config.demonize && !app.Demonize() )
|
||||||
return 4;
|
return 4;
|
||||||
|
|
||||||
|
log.SetTimeZones(&app.system.time_zones);
|
||||||
|
|
||||||
log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file,
|
log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file,
|
||||||
app.config.log_stdout, app.config.log_request);
|
app.config.log_stdout, app.config.log_request);
|
||||||
|
|
||||||
nlog.Init(app.config.log_level, true, app.config.log_notify_file, false, 1);
|
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() )
|
if( !app.InitFCGI() )
|
||||||
return 5;
|
return 5;
|
||||||
|
@ -124,13 +143,12 @@ int main(int argv, char ** argc)
|
||||||
if( !app.Init() )
|
if( !app.Init() )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
log << log1 << PT::Date(std::time(0)) << " winix started" << logend;
|
|
||||||
|
|
||||||
app.StartThreads();
|
app.StartThreads();
|
||||||
// now we have more threads, we should use Lock() and Unlock()
|
// now we have more threads, we should use Lock() and Unlock()
|
||||||
|
|
||||||
// saving all starting logs
|
// saving all starting logs
|
||||||
app.Lock();
|
app.Lock();
|
||||||
|
LogInfo(log1, "Winix", true, "started");
|
||||||
log << logsave;
|
log << logsave;
|
||||||
app.Unlock();
|
app.Unlock();
|
||||||
|
|
||||||
|
@ -146,7 +164,7 @@ int main(int argv, char ** argc)
|
||||||
app.WaitForThreads();
|
app.WaitForThreads();
|
||||||
// now all others threads are terminated
|
// now all others threads are terminated
|
||||||
|
|
||||||
log << log1 << PT::Date(std::time(0)) << " winix stopped" << logend << logsave;
|
LogInfo(log1, "Winix", true, "stopped");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue