I'm trying to setup my logging settings to send logging.info('any message')
to a file through 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:
import logging
logging.getLogger('app.location')
logging.info('any message')
It is not logged to the gunicorn_django
$LOGFILE. Just print >> sys.stderr
messages seem to be showed in the $LOGFILE
How can I log info messages (through stdout) to a file
Your logger is just getting garbage collected as soon as you create it. You need to keep a reference to it as a logger, and then use that logger, like so:
import logging
logger = logging.getLogger('app.location')
logger.info('any message')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With