Jameel Mohammed
Jameel Mohammed

Reputation: 2364

Gunicorn giving syntax error for my configuration file

my config file

[loggers]
keys=root, gunicorn.error, gunicorn.access

[handlers]
keys=console, error_file, access_file

[formatters]
keys=generic, access

[logger_root]
level=INFO
handlers=console

[logger_gunicorn.error]
level=INFO
handlers=error_file
propagate=1
qualname=gunicorn.error

[logger_gunicorn.access]
level=INFO
handlers=access_file
propagate=0
qualname=gunicorn.access

[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )

[handler_error_file]
class=logging.FileHandler
formatter=generic
args=('/tmp/gunicorn.error.log',)

[handler_access_file]
class=logging.FileHandler
formatter=access
args=('/tmp/gunicorn.access.log',)

[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter

[formatter_access]
format=%(message)s
class=logging.Formatter

My command to execute

gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi --log-level debug --log-file=- -c file:gunicorn_log.conf

Getting this error

Failed to read config file: gunicorn_log.conf
Traceback (most recent call last):
  File "/home/jameel/django-env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 93, in get_config_from_filename
    execfile_(filename, cfg, cfg)
  File "/home/jameel/django-env/local/lib/python2.7/site-packages/gunicorn/_compat.py", line 91, in execfile_
    return execfile(fname, *args)
  File "gunicorn_log.conf", line 27
    class=StreamHandler
         ^
SyntaxError: invalid syntax

I was followed as per their example in github link

Upvotes: 0

Views: 2108

Answers (2)

Jameel Mohammed
Jameel Mohammed

Reputation: 2364

[loggers]
keys=root, logstash.error, logstash.access

[handlers]
keys=console , logstash

[formatters]
keys=generic, access, json

[logger_root]
level=INFO
handlers=console

[logger_logstash.error]
level=DEBUG
handlers=logstash
propagate=1
qualname=gunicorn.error

[logger_logstash.access]
level=DEBUG
handlers=logstash
propagate=0
qualname=gunicorn.access


[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )

[handler_logstash]
class=logstash.TCPLogstashHandler
formatter=json
args=('localhost',5959)


[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter

[formatter_access]
format=%(message)s
class=logging.Formatter

[formatter_json]
class=jsonlogging.JSONFormatter

The above config file worked for me to send logs to logstash which is running under localhost:5959

Upvotes: 0

Tomasz Jakub Rup
Tomasz Jakub Rup

Reputation: 10680

Gunicorn config file looks like this: https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py

Your file is a logger configuration file.

Logger configuration is passed by --log-config parameter.

Upvotes: 1

Related Questions