[Patch] Option to not use the default error log file during startup

Maxim Dounin mdounin at mdounin.ru
Sat Nov 13 17:51:46 MSK 2010


Hello!

On Sat, Nov 13, 2010 at 03:20:10PM +0100, Hongli Lai wrote:

> Nginx always tries to open its default log file ($prefix/log/error.log)
> even if I specified a different error_log in the config file. This is
> done inside ngx_log_init(). This has two implications:
> 
> 1. All errors that occur before the error log - as specified in the
> config file - is opened, will be printed to the default error log and to
> stderr.
> 2. If the default error log cannot be opened, e.g. because of
> permissions, Nginx will print a warning.
> 
> (1) is fine for most cases where the user did not specify a different
> error log. Nginx will, in those cases, write pre-config-load errors to
> the error log file that the user expects as well as to stderr. However I
> have a setup in which many different users use the same Nginx
> executable, but each one with a different config file and error log
> file. Users do not have write permission to the default error log file,
> so because of (2), Nginx always prints the warning, which can be
> confusing to them.
> 
> Ideally I would like Nginx to always write to the error log file as
> specified in the config, and never to the default error log file, but it
> seems that the codebase does not allow this and assumes logging
> facilities to be available even before the config file is loaded.

Writing early errors to error_log as specified in config is not 
possible as we haven't (yet) parsed the config.

On the other hand, just passing errors only to stderr (as it was 
before 0.7.53) isn't believed (at least by Igor) to be sufficient 
as stderr is just lost in many cases (e.g. system startup).  This 
was rationale for the change in 0.7.53:

    *) Change: now a log set by --error-log-path is created from the very 
       start-up.

If you want nginx to log early errors only to stderr - you may 
recompile nginx with --error-log-path=stderr.

> Attached to this email is a patch which modifies ngx_log_init() to
> ignore the default error log file if the environment variable
> NGX_EARLY_LOG_TO_STDERR is set.

While I would like to see some way to redefine --error-log-path 
without recompilation - I don't like this particular aproach.

It would be good to have something like '-e' switch instead, 
similar to '-p' for prefix (actually, I even have it in my TODO 
since 0.7.53, but ENOTIME).

Maxim Dounin



More information about the nginx mailing list