1

I'm trying to log some info messages specifically in django settings.py. I'm following the first example in the django documentation that shows a simple configuration. The only thing I changed was having the log show INFO level messages. When I run python manage.py runserver, the log statement is never shown. The logs are only shown for WARNING level or above (more critical).

Here is my configuration that is located in settings.py

import logging
...
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    '': {
        'handlers': ['console'],
        'level': 'INFO',
        'propagate': True
    },
}
...
def do_something():
    logger.info('Doing Something')
do_something()

Note I'm trying to log statements only in my settings.py file as of right now.

Frantz Paul
  • 127
  • 2
  • 11

1 Answers1

0

Try Placing a level key inside the handler

    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
        },
    },

I just tested this on my Local Dev, My Logger looks like this [Chopped]: (Hopefully this helps!)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'filters': ['require_debug_true'],
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
        },
    }
}

def do():
    import logging
    logger = logging.getLogger('django')
    logger.info('TEST')
Nealium
  • 2,025
  • 1
  • 7
  • 9
  • Hi Nealiu, I tested your solution and it didn't work for me. Can you please share the exact code that works for you (or some minimal version)? I am using Django 4.1.4. – Mikolaj Buchwald Dec 29 '22 at 18:05