Opened 2 years ago

Closed 2 years ago

#34236 closed Uncategorized (invalid)

Django logging when in production with Gunnicron

Reported by: Derek Owned by: nobody
Component: Documentation Version: 4.1
Severity: Normal Keywords: logging
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Derek)

I was trying to configure access logs using Django logging as per documentation https://docs.djangoproject.com/en/4.1/howto/logging/
I wanted to collect all access logs from INFO. It works perfectly when in development mode. However, when I switched to Gunnicron in production, I got only warnings and higher status logs.

After a bit of searching, I have found this ticket below, which kind of summarises this behaviour.
https://code.djangoproject.com/ticket/33897
I think the documentation should say that once in production with Gunnicorn, there are no access logs with INFO status from the Django logger.

My logging configuration in settings.py is as follow:

#LOGGING SETTINGS
LOG_MAX_SIZE = int(os.getenv("LOG_MAX_SIZE")) #max size of single log file in bytes
LOG_NUMBER_OF_FILES = int(os.getenv("LOG_NUMBER_OF_FILES")) #number of old log files
LOG_LOCATION = os.getenv("LOG_LOCATION") #default name and location of a log file
LOG_LEVEL = os.getenv("LOG_LEVEL")

LOGGING = {
    'version': 1,  # the dictConfig format version
    'disable_existing_loggers': False,  # retain the default loggers

    'handlers': {
       'rotatingFile': {
            'level': LOG_LEVEL,
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            'maxBytes': LOG_MAX_SIZE,
            'backupCount': LOG_NUMBER_OF_FILES,
            'filename': LOG_LOCATION,
        }
    },
    'loggers': {
        
        'root': {
            'handlers': ['rotatingFile'],
            'level': LOG_LEVEL,
        },
        
    },
    'formatters': {
        'verbose': {
            'format': '{asctime} {levelname} {name} {module} {process:d} {thread:d} {message}',
            'style': '{',
        },
    },

.env file has the following entries:

#LOGGING SETTINGS
LOG_MAX_SIZE = 52428800 #max size of single log file in bytes
LOG_NUMBER_OF_FILES = 5 #number of old log files
LOG_LOCATION = '/logs/rotatingLog.log' #default name and location of a log file
LOG_LEVEL = 'INFO' #Log level to be collected through all django loggers - options include: DEBUG, INFO, WARNING, ERROR, CRITICAL

Change History (4)

comment:1 by Derek, 2 years ago

Description: modified (diff)

comment:2 by Derek, 2 years ago

Description: modified (diff)

comment:3 by Derek, 2 years ago

Description: modified (diff)

in reply to:  description comment:4 by Mariusz Felisiak, 2 years ago

Resolution: invalid
Status: newclosed

Replying to Derek:

I was trying to configure access logs using Django logging as per documentation https://docs.djangoproject.com/en/4.1/howto/logging/
I wanted to collect all access logs from INFO. It works perfectly when in development mode. However, when I switched to Gunnicron in production, I got only warnings and higher status logs.

It's not strictly related with Gunicorn, and it's already documented that the django.server logger logs "messages related to the handling of requests received by the server invoked by the runserver command."

Note: See TracTickets for help on using tickets.
Back to Top