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:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
33
core/log.cpp
33
core/log.cpp
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user