I recently met a logging issue about set logging level. I have a demo django project, which is to test set log level. below is the page:
The log will be written to /tmp/run.log.
When I deploy it with gunicoryn + nginx(proxy static file), and has 4 gunicorn workes. Set log level only have effect to one of the workers:
Above the two pictures, I set log level to ERROR
, but only effect worker 74096.
Here are some information and Django code.
System Info:
System: Centos 7.4 x64 Python: 2.7.5
Django: 1.11.2
Gunicorn: 19.7.1Django logging config:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s' } }, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'maxBytes': 1024, 'backupCount': 5, 'filename': '/tmp/run.log', 'formatter': 'verbose' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose'
set log level function
name = "django_docker" bind = "unix:/var/run/django_docker.sock" worker_class = "egg:meinheld#gunicorn_worker" #workers = multiprocessing.cpu_count() * 2 + 1 workers = 4 reload = True umask = 0002 user = 'nginx' group = 'nginx' accesslog = "/tmp/gunicorn.access.log" errorlog = "/tmp/gunicorn.error.log" raw_env = ["DJANGO_SETTINGS_MODULE=django_docker.settings"] chdir = " /home/user/workspace/django_docker/" pidfile = "/var/run/gunicorn.pid" daemon = True logconfig_dict = { 'version':1, 'disable_existing_loggers': False, 'loggers':{ "root": {"level": "INFO", "handlers": ["console"]}, "gunicorn.error": { "level": "INFO", "handlers": ["error_file"], "propagate": 1, "qualname": "gunicorn.error" }, "gunicorn.access": { "level": "INFO", "handlers": ["access_file"], "propagate": 0, "qualname": "gunicorn.access" } }, 'handlers':{ "console": { "class": "logging.StreamHandler", "formatter": "generic", "stream": "sys.stdout" }, "error_file": { "class": "logging.FileHandler", "formatter": "generic", "filename": "/tmp/gunicorn.error.log" }, "access_file": { "class": "logging.handlers.RotatingFileHandler", "maxBytes": 1024*1024, "backupCount": 5, "formatter": "generic", "filename": "/tmp/gunicorn.access.log", } }, 'formatters':{ "generic": { "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", "datefmt": "[%Y-%m-%d %H:%M:%S %z]", "class": "logging.Formatter" }, "access": { "format": "%(message)s", "class": "logging.Formatter" } } }
Also, I have try to deploy with uwsgi and 4 workers, Also have the problem.
Could anyone help with me, thanks.