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:
Tomasz Sowa 2012-09-06 17:50:14 +00:00
parent 0c6ddc2218
commit 9174555ff8
8 changed files with 77 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -11,6 +11,7 @@
#include <ctime>
#include <string.h>
#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)
{

View File

@ -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<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);
@ -67,6 +73,9 @@ public:
private:
// time zones for printing the time in the log file
TimeZones * time_zones;
// buffer for the log
TextStream<std::wstring> buffer;

View File

@ -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

View File

@ -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;
}