Skip to content
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

Gunicorn doesn't print access log to stdout/stderr #1400

Closed
msoedov opened this issue Nov 22, 2016 · 14 comments
Closed

Gunicorn doesn't print access log to stdout/stderr #1400

msoedov opened this issue Nov 22, 2016 · 14 comments

Comments

@msoedov
Copy link

msoedov commented Nov 22, 2016

I'm using containerized gunicorn process which I run by:

CMD gunicorn app:app -w 1 -b 0:44332 -t 300 --log-level debug --threads 5 --access-logfile - --error-logfile -

However I did manage to find an easy way in the docs how to make it print access log to stdout.
--access-logfile - doesn't work as it documented on http://docs.gunicorn.org/en/stable/settings.html#accesslog
Config for gunicorn==19.6.0

[2016-11-22 20:45:57 +0000] [7] [DEBUG] Current configuration:
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
  proxy_protocol: False
  worker_connections: 1000
  statsd_host: None
  max_requests_jitter: 0
  post_fork: <function post_fork at 0x7ff56a1a45f0>
  pythonpath: None
  enable_stdio_inheritance: False
  worker_class: sync
  ssl_version: 3
  suppress_ragged_eofs: True
  syslog: False
  syslog_facility: user
  when_ready: <function when_ready at 0x7ff56a1a4320>
  pre_fork: <function pre_fork at 0x7ff56a1a4488>
  cert_reqs: 0
  preload_app: False
  keepalive: 2
  accesslog: -
  group: 0
  graceful_timeout: 30
  do_handshake_on_connect: False
  spew: False
  workers: 1
  proc_name: None
  sendfile: None
  pidfile: None
  umask: 0
  on_reload: <function on_reload at 0x7ff56a1a41b8>
  pre_exec: <function pre_exec at 0x7ff56a1a4b90>
  worker_tmp_dir: None
  post_worker_init: <function post_worker_init at 0x7ff56a1a4758>
  limit_request_fields: 100
  on_exit: <function on_exit at 0x7ff56a1e62a8>
  config: None
  logconfig: None
  check_config: False
  statsd_prefix:
  proxy_allow_ips: ['127.0.0.1']
  pre_request: <function pre_request at 0x7ff56a1a4cf8>
  post_request: <function post_request at 0x7ff56a1a4de8>
  user: 0
  forwarded_allow_ips: ['127.0.0.1']
  worker_int: <function worker_int at 0x7ff56a1a48c0>
  threads: 5
  max_requests: 0
  limit_request_line: 4094
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  certfile: None
  worker_exit: <function worker_exit at 0x7ff56a1a4f50>
  chdir: /app
  paste: None
  default_proc_name: app:app
  errorlog: -
  loglevel: debug
  capture_output: False
  syslog_addr: udp://localhost:514
  syslog_prefix: None
  daemon: False
  ciphers: TLSv1
  on_starting: <function on_starting at 0x7ff56a1a4050>
  worker_abort: <function worker_abort at 0x7ff56a1a4a28>
  bind: ['0:44332']
  raw_env: []
  reload: False
  limit_request_field_size: 8190
  nworkers_changed: <function nworkers_changed at 0x7ff56a1e6140>
  timeout: 300
  ca_certs: None
  django_settings: None
  tmp_upload_dir: None
  keyfile: None
  backlog: 2048
  logger_class: gunicorn.glogging.Logger
@romabysen
Copy link
Contributor

I'm using Gunicorn with Amazon ECS and --access-logfile - works exactly as documented; it prints the accesslog to stderr.

@benoitc
Copy link
Owner

benoitc commented Jan 27, 2017

closing issue as "work as documented". Feel free to open a new one if you want to discuss a possible change of the current behaviour.

@benoitc benoitc closed this as completed Jan 27, 2017
@yamila-moreno
Copy link

Hi! I hope this is the proper place to ask about it; I'm using gunicorn (v19.7.1) and failing at finding logs in stdoutput. The command, as I understand the documentation is:

gunicorn -b 0.0.0.0:6007 --access-logfile - --error-logfile - --log-level debug 'wsgi:load_application()' 

Then, when I make any http request to the application I cannot see any log in the gunicorn terminal (although the application is responding properly to the request).
I've also tried with export PYTHONUNBUFFERED with same result.

Am I using gunicorn wrong? Could anyone provide a hint? Thanks in advance!!

@berkerpeksag
Copy link
Collaborator

@yamila-moreno I just tried the command you pasted with examples/test.py and I was able to see access logs in the terminal:

$ gunicorn -b 0.0.0.0:6007 --access-logfile - --error-logfile - --log-level debug test:app
[2018-03-22 17:42:29 +0300] [24642] [DEBUG] Current configuration:
[...snipped...]
[2018-03-22 17:42:29 +0300] [24642] [INFO] Starting gunicorn 19.7.1
[2018-03-22 17:42:29 +0300] [24642] [DEBUG] Arbiter booted
[2018-03-22 17:42:29 +0300] [24642] [INFO] Listening at: http://0.0.0.0:6007 (24642)
[2018-03-22 17:42:29 +0300] [24642] [INFO] Using worker: sync
[2018-03-22 17:42:29 +0300] [24645] [INFO] Booting worker with pid: 24645
[2018-03-22 17:42:29 +0300] [24642] [DEBUG] 1 workers
[2018-03-22 17:42:32 +0300] [24645] [DEBUG] GET /
127.0.0.1 - - [22/Mar/2018:17:42:32 +0300] "GET / HTTP/1.1" 200 14 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
[2018-03-22 17:42:33 +0300] [24645] [DEBUG] GET /favicon.ico
127.0.0.1 - - [22/Mar/2018:17:42:33 +0300] "GET /favicon.ico HTTP/1.1" 200 14 "http://0.0.0.0:6007/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
[2018-03-22 17:42:39 +0300] [24645] [DEBUG] GET /
127.0.0.1 - - [22/Mar/2018:17:42:39 +0300] "GET / HTTP/1.1" 200 14 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
[2018-03-22 17:42:40 +0300] [24645] [DEBUG] GET /favicon.ico
127.0.0.1 - - [22/Mar/2018:17:42:40 +0300] "GET /favicon.ico HTTP/1.1" 200 14 "http://0.0.0.0:6007/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

@yamila-moreno
Copy link

@berkerpeksag thanks for your answer. I was hoping I just misunderstood the documentation. At least I can stop looking there, and find the error in another place. When (if) I finally find the solution, I'll paste here, so it may be useful for someone.

@yamila-moreno
Copy link

@berkerpeksag sorry for bothering with this, but could you paste also the first part of your gunicorn command? the part "...snipped..."; I'd like to check if there is anything different that I could use as a hint.

thanks!!

@berkerpeksag
Copy link
Collaborator

Here it is:

  keepalive: 2
  pidfile: None
  config: None
  keyfile: None
  enable_stdio_inheritance: False
  threads: 1
  preload_app: False
  initgroups: False
  worker_abort: <function WorkerAbort.worker_abort at 0x7fd287b241e0>
  post_request: <function PostRequest.post_request at 0x7fd287b24620>
  nworkers_changed: <function NumWorkersChanged.nworkers_changed at 0x7fd287b24ae8>
  cert_reqs: 0
  statsd_prefix: 
  ssl_version: 2
  suppress_ragged_eofs: True
  ciphers: TLSv1
  worker_connections: 1000
  max_requests: 0
  on_exit: <function OnExit.on_exit at 0x7fd287b24c80>
  timeout: 30
  chdir: /home/berker/projects/gunicorn/examples
  raw_env: []
  group: 1000
  forwarded_allow_ips: ['127.0.0.1']
  accesslog: -
  capture_output: False
  pre_exec: <function PreExec.pre_exec at 0x7fd287b24378>
  worker_tmp_dir: None
  post_fork: <function Postfork.post_fork at 0x7fd287b1cc80>
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-SSL': 'on', 'X-FORWARDED-PROTO': 'https'}
  default_proc_name: test:app
  worker_int: <function WorkerInt.worker_int at 0x7fd287b24048>
  errorlog: -
  loglevel: debug
  syslog_prefix: None
  syslog_facility: user
  on_starting: <function OnStarting.on_starting at 0x7fd287b1c620>
  worker_exit: <function WorkerExit.worker_exit at 0x7fd287b24950>
  paste: None
  backlog: 2048
  sendfile: None
  user: 1000
  workers: 1
  syslog_addr: udp://localhost:514
  limit_request_fields: 100
  statsd_host: None
  proc_name: None
  check_config: False
  when_ready: <function WhenReady.when_ready at 0x7fd287b1c950>
  child_exit: <function ChildExit.child_exit at 0x7fd287b247b8>
  proxy_protocol: False
  limit_request_field_size: 8190
  raw_paste_global_conf: []
  reload: False
  spew: False
  ca_certs: None
  proxy_allow_ips: ['127.0.0.1']
  limit_request_line: 4094
  reload_engine: auto
  daemon: False
  umask: 0
  tmp_upload_dir: None
  logger_class: gunicorn.glogging.Logger
  pre_fork: <function Prefork.pre_fork at 0x7fd287b1cae8>
  post_worker_init: <function PostWorkerInit.post_worker_init at 0x7fd287b1ce18>
  worker_class: sync
  pre_request: <function PreRequest.pre_request at 0x7fd287b24510>
  logconfig: None
  do_handshake_on_connect: False
  max_requests_jitter: 0
  certfile: None
  graceful_timeout: 30
  bind: ['0.0.0.0:6007']
  on_reload: <function OnReload.on_reload at 0x7fd287b1c7b8>
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  pythonpath: None
  syslog: False

@yamila-moreno
Copy link

Hi there!! @berkerpeksag thanks for your help. I realised that the problem was the configuration with the logging package.
Then I found this post which helped me to configure this properly.

@dave4jr
Copy link

dave4jr commented Dec 10, 2018

@berkerpeksag @benoitc Hey guys, is there a way to disable the current configuration from being printed out when on DEBUG log level? (similar to the snipped section above).

@secsilm
Copy link

secsilm commented Dec 10, 2019

FYI, if you use logging.config.fileConfig() or logging.config.dictConfig(), then you should set disable_existing_loggers to False. If it's True, it will disable gunicorn logger. For detail please see Logging HOWTO — Python 3.8.1rc1 documentation.

@benoitc
Copy link
Owner

benoitc commented Dec 10, 2019

@dave4jr nope, why?

@danalexandrucraciun
Copy link

I'm using Gunicorn with Amazon ECS and --access-logfile - works exactly as documented; it prints the accesslog to stderr.

@romabysen interesting. Do you still have the command?

I'm using the container with my gunicorn in ecs, and I have a startup.sh in docker file with this command to start the server, but it's not delivering the log to stdout.

This is my dockerfile:

image

This is the server :

image

@danalexandrucraciun
Copy link

@msoedov did you find the solution to print the log in stdout using the containerized gunicorn?

@muhammad-asn
Copy link

muhammad-asn commented Aug 10, 2022

Yes using --access-logfile - --error-logfile - it works. @danalexandrucraciun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants