New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I print accesslog to STDOUT? #1184

Closed
lamroger opened this Issue Jan 19, 2016 · 22 comments

Comments

Projects
None yet
@lamroger

lamroger commented Jan 19, 2016

Hi,

http://docs.gunicorn.org/en/stable/settings.html#accesslog is telling me '-' will output to stderr but we prefer STDOUT for logging purposes. Is there a way to do that?

Thanks!

@berkerpeksag

This comment has been minimized.

Show comment
Hide comment
@berkerpeksag

berkerpeksag Jan 19, 2016

Collaborator

The relevant line is here: https://github.com/benoitc/gunicorn/blame/master/gunicorn/glogging.py#L335 logging.StreamHandler() defaults to sys.stderr. Perhaps we could change accesslog to accept "stdout" and "stderr" as valid values and pass to logging.StreamHandler().

Collaborator

berkerpeksag commented Jan 19, 2016

The relevant line is here: https://github.com/benoitc/gunicorn/blame/master/gunicorn/glogging.py#L335 logging.StreamHandler() defaults to sys.stderr. Perhaps we could change accesslog to accept "stdout" and "stderr" as valid values and pass to logging.StreamHandler().

@berkerpeksag

This comment has been minimized.

Show comment
Hide comment
@berkerpeksag

berkerpeksag Jan 19, 2016

Collaborator

Another but less flexible solution:

The console handler already prints to sys.stdout: https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L64 We could set the handler to "console" for gunicorn.accesslog as we already did for gunicorn.error in https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L55

Collaborator

berkerpeksag commented Jan 19, 2016

Another but less flexible solution:

The console handler already prints to sys.stdout: https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L64 We could set the handler to "console" for gunicorn.accesslog as we already did for gunicorn.error in https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L55

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Jan 19, 2016

Owner

I'm confused. Doesn't the StreamHandler already log on sys.stdout?

Owner

benoitc commented Jan 19, 2016

I'm confused. Doesn't the StreamHandler already log on sys.stdout?

@berkerpeksag

This comment has been minimized.

Show comment
Hide comment
@berkerpeksag
Collaborator

berkerpeksag commented Jan 19, 2016

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Jan 22, 2016

Owner

OK I understand now. Originally we were printing logs to stdout. IMO the access log should default to STDOUT. Thoughts?

Owner

benoitc commented Jan 22, 2016

OK I understand now. Originally we were printing logs to stdout. IMO the access log should default to STDOUT. Thoughts?

@tilgovi

This comment has been minimized.

Show comment
Hide comment
@tilgovi

tilgovi Feb 11, 2016

Collaborator

@benoitc 👍

Access log on stdout
Error log on stderr

Collaborator

tilgovi commented Feb 11, 2016

@benoitc 👍

Access log on stdout
Error log on stderr

@emanuelcds

This comment has been minimized.

Show comment
Hide comment
@emanuelcds

emanuelcds Apr 14, 2016

any updates on this request?

emanuelcds commented Apr 14, 2016

any updates on this request?

@benoitc benoitc closed this in 65db610 May 2, 2016

@suriya

This comment has been minimized.

Show comment
Hide comment
@suriya

suriya May 11, 2016

Contributor

@benoitc I am not sure this commit addresses this issue. Let us say I run, gunicorn myapp:app with no additional arguments. Is the expectation that gunicorn should log access records to standard output? If so, gunicorn doesn't do that.

In https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L302 without any command line arguments self.cfg.accesslog is None and the function returns early. As far as I can tell, there seems to be no way to log to stdout without specifing --log-config or --log-syslog. Is this correct?

Contributor

suriya commented May 11, 2016

@benoitc I am not sure this commit addresses this issue. Let us say I run, gunicorn myapp:app with no additional arguments. Is the expectation that gunicorn should log access records to standard output? If so, gunicorn doesn't do that.

In https://github.com/benoitc/gunicorn/blob/master/gunicorn/glogging.py#L302 without any command line arguments self.cfg.accesslog is None and the function returns early. As far as I can tell, there seems to be no way to log to stdout without specifing --log-config or --log-syslog. Is this correct?

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc May 30, 2016

Owner

by default access log is disabled if this is what you mean?

Owner

benoitc commented May 30, 2016

by default access log is disabled if this is what you mean?

@suriya

This comment has been minimized.

Show comment
Hide comment
@suriya

suriya May 30, 2016

Contributor

@benoitc Yes. The discussion above seems to indicate that access logs will go to stdout and error logs to stderr. However, it looks like access logging is disabled by default.

BTW, with Python 2.7 I used to be able to do --access-log /dev/stdout --error-log /dev/stderr and that would work. With Python 3, passing /dev/stdout as an argument fails in

f = open(path, 'a')

Contributor

suriya commented May 30, 2016

@benoitc Yes. The discussion above seems to indicate that access logs will go to stdout and error logs to stderr. However, it looks like access logging is disabled by default.

BTW, with Python 2.7 I used to be able to do --access-log /dev/stdout --error-log /dev/stderr and that would work. With Python 3, passing /dev/stdout as an argument fails in

f = open(path, 'a')

@amilstead

This comment has been minimized.

Show comment
Hide comment
@amilstead

amilstead Jul 13, 2016

👍 @suriya I think I'm looking for the same behavior you are -- I'd like to run --capture-log and enable --access-logfile=<something>, but I'd prefer my access log lines go to stdout not stderr.

EDIT: To clarify, this appears to just be a problem with Python3. Using python3.5.1, passing --access-logfile=/dev/stdout to gunicorn fails to start the server.

amilstead commented Jul 13, 2016

👍 @suriya I think I'm looking for the same behavior you are -- I'd like to run --capture-log and enable --access-logfile=<something>, but I'd prefer my access log lines go to stdout not stderr.

EDIT: To clarify, this appears to just be a problem with Python3. Using python3.5.1, passing --access-logfile=/dev/stdout to gunicorn fails to start the server.

@huoxy

This comment has been minimized.

Show comment
Hide comment
@huoxy

huoxy Jul 26, 2016

Yes, it looks like access logging is disabled by default.

huoxy commented Jul 26, 2016

Yes, it looks like access logging is disabled by default.

@suriya

This comment has been minimized.

Show comment
Hide comment
@suriya

suriya Jul 27, 2016

Contributor

@huoxy More than what the default is, I think the issue is more that there is no simple way to write access logs to standard output.

Contributor

suriya commented Jul 27, 2016

@huoxy More than what the default is, I think the issue is more that there is no simple way to write access logs to standard output.

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Jul 27, 2016

Owner

@huoxy ˋ--access-logfile=-` should do the trick. let me k'ow if not.

@huoxy https://github.com/huoxy More than what the default is, I think
the issue is more that there is no simple way to write access logs to
standard output.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1184 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.

Owner

benoitc commented Jul 27, 2016

@huoxy ˋ--access-logfile=-` should do the trick. let me k'ow if not.

@huoxy https://github.com/huoxy More than what the default is, I think
the issue is more that there is no simple way to write access logs to
standard output.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1184 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.

@benoitc

This comment has been minimized.

Show comment
Hide comment
@benoitc

benoitc Jul 27, 2016

Owner

also it is probably a doc issue. but access log must be printed to stdout
when - is used. otherwise it is a bug. Let me know...
On Wed, 27 Jul 2016 at 09:03, Benoit Chesneau bchesneau@gmail.com wrote:

@huoxy ˋ--access-logfile=-` should do the trick. let me k'ow if not.

@huoxy https://github.com/huoxy More than what the default is, I think
the issue is more that there is no simple way to write access logs to
standard output.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1184 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.

Owner

benoitc commented Jul 27, 2016

also it is probably a doc issue. but access log must be printed to stdout
when - is used. otherwise it is a bug. Let me know...
On Wed, 27 Jul 2016 at 09:03, Benoit Chesneau bchesneau@gmail.com wrote:

@huoxy ˋ--access-logfile=-` should do the trick. let me k'ow if not.

@huoxy https://github.com/huoxy More than what the default is, I think
the issue is more that there is no simple way to write access logs to
standard output.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1184 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA4oj67GbLqwaJaCQ9NOH7-iAXJoMxGks5qZv9fgaJpZM4HHW4G
.

@suriya

This comment has been minimized.

Show comment
Hide comment
@suriya

suriya Jul 27, 2016

Contributor

@benoitc As mentioned in #1293, gunicorn --access-log - logs accesses to standard error. I tried with gunicorn --access-log=- and the log still goes to standard error.

Contributor

suriya commented Jul 27, 2016

@benoitc As mentioned in #1293, gunicorn --access-log - logs accesses to standard error. I tried with gunicorn --access-log=- and the log still goes to standard error.

benoitc added a commit that referenced this issue Jul 27, 2016

make sure access logs are printed to stdout
logging.StreamHandler deault to sys.stderr, so make sure access log are printed to stdout when choosing "-" by forcing the stream.

Note: access logs were printed to stdout by default when using the config file.

fix #1184
@BeOleg

This comment has been minimized.

Show comment
Hide comment
@BeOleg

BeOleg Jan 27, 2017

according to this:
https://github.com/gunicorn/gunicorn/blob/master/gunicorn/glogging.py#L58

default logger is console which outputs to stdout, so I guess if you need everything to stdout like me, for everything to get to the gunicorn logging driver, you can just leave those options blank.

BeOleg commented Jan 27, 2017

according to this:
https://github.com/gunicorn/gunicorn/blob/master/gunicorn/glogging.py#L58

default logger is console which outputs to stdout, so I guess if you need everything to stdout like me, for everything to get to the gunicorn logging driver, you can just leave those options blank.

@BeOleg

This comment has been minimized.

Show comment
Hide comment
@BeOleg

BeOleg Jan 27, 2017

Also, the solution I would suggest, is to create a symbolic link for the log files to /dev/stdout or /dev/stderror if it does not work directly:

ln -sf /var/log/gunicorn.access.log  /dev/stdout
ln -sf /var/log/gunicorn.error.log  /dev/stdout

exec newrelic-admin run-program gunicorn --chdir /usr/src/app --name nexchange --bind 0.0.0.0:${GUNICORN_PORT} --workers 3 --log-level=info --log-file=/var/log/gunicorn.error.log --access-logfile=/var/log/gunicorn.access.log nexchange.wsgi:application "$@"

BeOleg commented Jan 27, 2017

Also, the solution I would suggest, is to create a symbolic link for the log files to /dev/stdout or /dev/stderror if it does not work directly:

ln -sf /var/log/gunicorn.access.log  /dev/stdout
ln -sf /var/log/gunicorn.error.log  /dev/stdout

exec newrelic-admin run-program gunicorn --chdir /usr/src/app --name nexchange --bind 0.0.0.0:${GUNICORN_PORT} --workers 3 --log-level=info --log-file=/var/log/gunicorn.error.log --access-logfile=/var/log/gunicorn.access.log nexchange.wsgi:application "$@"
@Ghazgkull

This comment has been minimized.

Show comment
Hide comment
@Ghazgkull

Ghazgkull Mar 10, 2017

I just moved to gunicorn 19.7.0 released last week. Unfortunately, I still can't get the access log written to anything other than stderr.

I've tried running gunicorn with no options and also with all permutations of including/not including "--access-logfile=- --error-logfile=- --log-level=DEBUG".

Am I missing something basic about gunicorn's logging? Is something from my environment or from Django possibly bleeding over and causing this problem?

Ghazgkull commented Mar 10, 2017

I just moved to gunicorn 19.7.0 released last week. Unfortunately, I still can't get the access log written to anything other than stderr.

I've tried running gunicorn with no options and also with all permutations of including/not including "--access-logfile=- --error-logfile=- --log-level=DEBUG".

Am I missing something basic about gunicorn's logging? Is something from my environment or from Django possibly bleeding over and causing this problem?

@suriya

This comment has been minimized.

Show comment
Hide comment
@suriya

suriya Mar 10, 2017

Contributor

With the application file myapp.py, I tried the following.

$ python --version
Python 3.5.2
$ gunicorn --version
gunicorn (version 19.7.0)
$ gunicorn --access-logfile - myapp:app 

I can confirm that the access log output goes to stdout.

Contributor

suriya commented Mar 10, 2017

With the application file myapp.py, I tried the following.

$ python --version
Python 3.5.2
$ gunicorn --version
gunicorn (version 19.7.0)
$ gunicorn --access-logfile - myapp:app 

I can confirm that the access log output goes to stdout.

@Ghazgkull

This comment has been minimized.

Show comment
Hide comment
@Ghazgkull

Ghazgkull Oct 2, 2017

I'm on Python 2.7.14. (Somehow missed the quick reply months ago.)

Ghazgkull commented Oct 2, 2017

I'm on Python 2.7.14. (Somehow missed the quick reply months ago.)

@deka108

This comment has been minimized.

Show comment
Hide comment
@deka108

deka108 Nov 6, 2017

You can also use accesslog = "-" in your gunicorn.config.py

deka108 commented Nov 6, 2017

You can also use accesslog = "-" in your gunicorn.config.py

fofanov pushed a commit to fofanov/gunicorn that referenced this issue Mar 16, 2018

fofanov pushed a commit to fofanov/gunicorn that referenced this issue Mar 16, 2018

make sure access logs are printed to stdout
logging.StreamHandler deault to sys.stderr, so make sure access log are printed to stdout when choosing "-" by forcing the stream.

Note: access logs were printed to stdout by default when using the config file.

fix #1184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment