Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 37e1c36

Browse files
committed
log: initialize logging earlier
It turns out to be possible to initialize logging earlier by grabbing the log from a global ngx_cycle structure. This makes us start logging earlier, yet loses the "No threading detected ..." messages both from stderr and in error.log when nginx initially starts. With this change, these messages will now be logged as we start logging earlier: " flush . " These originate from SystemCachePath::CacheKey which appends newlines to the key, and the resulting cache key ends up being logged. We might want to change that, because the resulting lines in error.log look weird and might raise questions. Fixes #895
1 parent f88a076 commit 37e1c36

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/ngx_pagespeed.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ void* ps_create_main_conf(ngx_conf_t* cf) {
983983
"" /* hostname, not used */,
984984
-1 /* port, not used */);
985985
active_driver_factory = cfg_m->driver_factory;
986+
active_driver_factory->LoggingInit(ngx_cycle->log, false);
986987
cfg_m->driver_factory->Init();
987988
ps_set_conf_cleanup_handler(cf, ps_cleanup_main_conf, cfg_m);
988989
return cfg_m;
@@ -3044,7 +3045,7 @@ ngx_int_t ps_init_module(ngx_cycle_t* cycle) {
30443045
return NGX_ERROR;
30453046
}
30463047

3047-
cfg_m->driver_factory->LoggingInit(cycle->log);
3048+
cfg_m->driver_factory->LoggingInit(cycle->log, true);
30483049
cfg_m->driver_factory->RootInit();
30493050
} else {
30503051
delete cfg_m->driver_factory;
@@ -3076,7 +3077,7 @@ ngx_int_t ps_init_child_process(ngx_cycle_t* cycle) {
30763077

30773078
// ChildInit() will initialise all ServerContexts, which we need to
30783079
// create ProxyFetchFactories below
3079-
cfg_m->driver_factory->LoggingInit(cycle->log);
3080+
cfg_m->driver_factory->LoggingInit(cycle->log, true);
30803081
cfg_m->driver_factory->ChildInit();
30813082

30823083
ngx_http_core_main_conf_t* cmcf = static_cast<ngx_http_core_main_conf_t*>(

src/ngx_rewrite_driver_factory.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ void NgxRewriteDriverFactory::StartThreads() {
208208
threads_started_ = true;
209209
}
210210

211-
void NgxRewriteDriverFactory::LoggingInit(ngx_log_t* log) {
211+
void NgxRewriteDriverFactory::LoggingInit(
212+
ngx_log_t* log, bool may_install_crash_handler) {
212213
log_ = log;
213214
net_instaweb::log_message_handler::Install(log);
214-
if (install_crash_handler()) {
215+
if (may_install_crash_handler && install_crash_handler()) {
215216
NgxMessageHandler::InstallCrashHandler(log);
216217
}
217218
ngx_message_handler_->set_log(log);

src/ngx_rewrite_driver_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class NgxRewriteDriverFactory : public SystemRewriteDriverFactory {
115115
return process_script_variables_;
116116
}
117117

118-
void LoggingInit(ngx_log_t* log);
118+
void LoggingInit(ngx_log_t* log, bool may_install_crash_handler);
119119

120120
virtual void ShutDownMessageHandlers();
121121

0 commit comments

Comments
 (0)