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

**URL:** <https://www.ruby-forum.com/t/patch-option-to-not-use-the-default-error-log-file-during-startup/199060>\
**Category:** NGINX\
**Created:** [November 13, 2010, 3:20pm UTC](https://www.ruby-forum.com/t/patch-option-to-not-use-the-default-error-log-file-during-startup/199060 "2010-11-13T15:20:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 13, 2010, 3:20pm UTC](https://www.ruby-forum.com/t/patch-option-to-not-use-the-default-error-log-file-during-startup/199060/1 "2010-11-13T15:20:10Z")

</div>

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.

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.

---

<div class="post-metadata">

**Author:** ![foobarwidget](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71c47a/32.png) [@foobarwidget](https://www.ruby-forum.com/u/foobarwidget)\
**Post date:** [November 13, 2010, 3:52pm UTC](https://www.ruby-forum.com/t/patch-option-to-not-use-the-default-error-log-file-during-startup/199060/2 "2010-11-13T15:52:51Z")

</div>

Hello!

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

> (1) is fine for most cases where the user did not specify a different  
> 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 D.

---

<div class="post-metadata">

**Author:** ![foobarwidget](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71c47a/32.png) [@foobarwidget](https://www.ruby-forum.com/u/foobarwidget)\
**Post date:** [November 18, 2010, 2:40am UTC](https://www.ruby-forum.com/t/patch-option-to-not-use-the-default-error-log-file-during-startup/199060/3 "2010-11-18T02:40:10Z")

</div>

Maxim D. wrote in post #961194:

> 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).

Ah I didn’t know about -p. I’m using that now and it solves my problem.  
Thanks.
