nghttpx: Don't cache time for logging

Update is done by main event loop which is stopped after graceful
shutdown is commenced, which means time is no longer update.  To avoid
this situation, we just avoid caching and get time for each logging.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-06 23:17:09 +09:00
parent e8107b68c8
commit ba795d86f0
3 changed files with 6 additions and 16 deletions

View File

@ -421,19 +421,11 @@ void graceful_shutdown_signal_cb(struct ev_loop *loop, ev_signal *w,
}
} // namespace
namespace {
std::unique_ptr<std::string> generate_time() {
return util::make_unique<std::string>(
util::format_common_log(std::chrono::system_clock::now()));
}
} // namespace
namespace {
void refresh_cb(struct ev_loop *loop, ev_timer *w, int revents) {
auto listener_handler = static_cast<ListenHandler *>(w->data);
auto worker_stat = listener_handler->get_worker_stat();
mod_config()->cached_time = generate_time();
// In multi threaded mode (get_config()->num_worker > 1), we have to
// wait for event notification to workers to finish.
if (get_config()->num_worker == 1 && worker_config->graceful_shutdown &&
@ -698,7 +690,6 @@ void fill_default_config() {
nghttp2_option_set_no_auto_window_update(mod_config()->http2_option, 1);
mod_config()->tls_proto_mask = 0;
mod_config()->cached_time = generate_time();
mod_config()->no_location_rewrite = false;
mod_config()->argc = 0;
mod_config()->argv = nullptr;

View File

@ -169,7 +169,6 @@ struct Config {
std::vector<std::pair<std::string, std::string>> add_response_headers;
std::vector<unsigned char> alpn_prefs;
std::vector<LogFragment> accesslog_format;
std::shared_ptr<std::string> cached_time;
std::vector<DownstreamAddr> downstream_addrs;
// binary form of http proxy host and port
sockaddr_union downstream_http_proxy_addr;

View File

@ -122,16 +122,16 @@ Log::~Log() {
char buf[4096];
auto tty = wconf->errorlog_tty;
auto cached_time = get_config()->cached_time;
auto time_now = util::format_common_log(std::chrono::system_clock::now());
if (severity_ == NOTICE) {
rv = snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s\n",
cached_time->c_str(), get_config()->pid,
tty ? SEVERITY_COLOR[severity_] : "", SEVERITY_STR[severity_],
tty ? "\033[0m" : "", stream_.str().c_str());
rv = snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s\n", time_now.c_str(),
get_config()->pid, tty ? SEVERITY_COLOR[severity_] : "",
SEVERITY_STR[severity_], tty ? "\033[0m" : "",
stream_.str().c_str());
} else {
rv = snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s%s:%d%s %s\n",
cached_time->c_str(), get_config()->pid,
time_now.c_str(), get_config()->pid,
tty ? SEVERITY_COLOR[severity_] : "", SEVERITY_STR[severity_],
tty ? "\033[0m" : "", tty ? "\033[1;30m" : "", filename_,
linenum_, tty ? "\033[0m" : "", stream_.str().c_str());