Commit 6519cced authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[log]: supported "localtime" (--log-show-localtime)

parent f52085f5
......@@ -175,6 +175,12 @@ class DebugStream : public std::ostream
show_datetime = s;
}
// false = UTC (by default)
inline void showLocalTime( bool s ) noexcept
{
show_localtime = s;
}
inline void showMilliseconds( bool s ) noexcept
{
show_msec = s;
......@@ -296,6 +302,7 @@ class DebugStream : public std::ostream
bool show_logtype = { true };
bool show_msec = { false };
bool show_usec = { false };
bool show_localtime = { false };
std::string fname = { "" };
StreamEvent_Signal s_stream;
......
......@@ -65,6 +65,7 @@ std::string uniset::Configuration::help()
print_help(os, 25, "--ulog-del-levels", "удалить уровень вывода логов\n");
print_help(os, 25, "--ulog-show-microseconds", "Выводить время с микросекундами\n");
print_help(os, 25, "--ulog-show-milliseconds", "Выводить время с миллисекундами\n");
print_help(os, 25, "--ulog-show-localtime", "Выводить локальное время. По умолчанию UTC.\n");
print_help(os, 25, "--ulog-no-debug", "отключение логов\n");
print_help(os, 25, "--ulog-logfile", "перенаправление лога в файл\n");
print_help(os, 25, "--ulog-levels N", "уровень 'говорливости' логов");
......@@ -913,7 +914,7 @@ namespace uniset
if(!node)
{
ucrit << "(Configuration): <nodes> section not found!" << endl;
throw uniset::SystemError("(Configiuration): <nodes> section not found");
throw uniset::SystemError("(Configuration): <nodes> section not found");
}
UniXML::iterator it(node);
......@@ -1067,6 +1068,9 @@ namespace uniset
deb->addLevel(Debug::NONE);
debug_file = getProp(dnode, "file");
if( getPIntProp(dnode, "showLocalTime", 0) != 0 )
deb->showLocalTime(true);
}
// теперь смотрим командную строку
......@@ -1076,6 +1080,7 @@ namespace uniset
const string show_msec("--" + debname + "-show-milliseconds");
const string show_usec("--" + debname + "-show-microseconds");
const string verb_level("--" + debname + "-verbosity");
const string show_localtime("--" + debname + "-show-localtime");
// смотрим командную строку
for (int i = 1; i < (_argc - 1); i++)
......@@ -1104,6 +1109,10 @@ namespace uniset
{
deb->verbose(uniset::uni_atoi(_argv[i + 1]));
}
else if( show_localtime == _argv[i] )
{
deb->showLocalTime(uniset::uni_atoi(_argv[i + 1]));
}
}
if( !debug_file.empty() )
......
......@@ -211,7 +211,10 @@ std::ostream& DebugStream::printDate(Debug::type t, char brk) noexcept
std::time_t tv = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm tms;
gmtime_r(&tv, &tms);
if( show_localtime )
localtime_r(&tv, &tms);
else
gmtime_r(&tv, &tms);
#if __GNUC__ >= 5
std::ostringstream fmt;
......@@ -235,7 +238,10 @@ std::ostream& DebugStream::printTime(Debug::type t, char brk) noexcept
timespec tv = uniset::now_to_timespec(); // gettimeofday(tv,0);
std::tm tms;
gmtime_r(&tv.tv_sec, &tms);
if( show_localtime )
localtime_r(&tv.tv_sec, &tms);
else
gmtime_r(&tv.tv_sec, &tms);
#if __GNUC__ >= 5
std::ostringstream fmt;
......@@ -266,7 +272,10 @@ std::ostream& DebugStream::printDateTime(Debug::type t) noexcept
timespec tv = uniset::now_to_timespec(); // gettimeofday(tv,0);
std::tm tms;
gmtime_r(&tv.tv_sec, &tms);
if( show_localtime )
localtime_r(&tv.tv_sec, &tms);
else
gmtime_r(&tv.tv_sec, &tms);
#if __GNUC__ >= 5
*this << std::put_time(&tms, "%Od/%Om/%Y %OH:%OM:%OS");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment