nghttpx: Update log time stamp in millisecond interval

This commit is contained in:
Tatsuhiro Tsujikawa 2017-02-17 00:18:07 +09:00
parent 1133cc0bbc
commit ace40f298d
3 changed files with 20 additions and 1 deletions

View File

@ -141,7 +141,7 @@ Log::~Log() {
char buf[4_k]; char buf[4_k];
auto tty = lgconf->errorlog_tty; auto tty = lgconf->errorlog_tty;
lgconf->update_tstamp(std::chrono::system_clock::now()); lgconf->update_tstamp_millis(std::chrono::system_clock::now());
// Error log format: <datetime> <master-pid> <current-pid> // Error log format: <datetime> <master-pid> <current-pid>
// <thread-id> <level> (<filename>:<line>) <msg> // <thread-id> <level> (<filename>:<line>) <msg>

View File

@ -96,6 +96,20 @@ LogConfig *log_config() { return config.get(); }
void delete_log_config() {} void delete_log_config() {}
#endif // NOTHREADS #endif // NOTHREADS
void LogConfig::update_tstamp_millis(
const std::chrono::system_clock::time_point &now) {
if (std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch()) ==
std::chrono::duration_cast<std::chrono::milliseconds>(
time_str_updated.time_since_epoch())) {
return;
}
time_str_updated = now;
tstamp = std::make_shared<Timestamp>(now);
}
void LogConfig::update_tstamp( void LogConfig::update_tstamp(
const std::chrono::system_clock::time_point &now) { const std::chrono::system_clock::time_point &now) {
auto t0 = std::chrono::system_clock::to_time_t(time_str_updated); auto t0 = std::chrono::system_clock::to_time_t(time_str_updated);

View File

@ -59,6 +59,11 @@ struct LogConfig {
bool errorlog_tty; bool errorlog_tty;
LogConfig(); LogConfig();
// Updates time stamp if difference between time_str_updated and now
// is 1 or more milliseconds.
void update_tstamp_millis(const std::chrono::system_clock::time_point &now);
// Updates time stamp if difference between time_str_updated and
// now, converted to time_t, is 1 or more seconds.
void update_tstamp(const std::chrono::system_clock::time_point &now); void update_tstamp(const std::chrono::system_clock::time_point &now);
}; };