Gunicorn Django and writing information to a file

I am trying to configure my logging options to send logging.info('any message') to a file via stdout .

This is my gunicorn_django script:

$ gunicorn_django -w $NUM_WORKERS --user=$USER --group=$GROUP --log-level=info --log-file=$LOGFILE &>>$LOGFILE

These are my logging settings:

 import sys LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'simple': { 'format': '%(levelname)s %(message)s' }, }, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'console': { 'level': 'INFO', 'filters': ['require_debug_false'], 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'simple', }, 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'app.location': { 'handlers': ['console'], 'level': 'INFO', 'propagate': False, }, 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } 

When I do this:

 import logging logging.getLogger('app.location') logging.info('any message') 

It is not registered with gunicorn_django $ LOGFILE. Just print >> sys.stderr displayed in the $ LOGFILE file

How can I log informational messages (via stdout) in a file

+6
source share
1 answer

Your registrar simply collects garbage as soon as you create it. You need to save the link to it as a registrar, and then use this registrar, for example:

 import logging logger = logging.getLogger('app.location') logger.info('any message') 
+4
source

Source: https://habr.com/ru/post/944551/


All Articles