How to see every activity in logs of Django 2.0.6?

114 views
Skip to first unread message

prateek gupta

unread,
Jul 26, 2018, 1:20:07 AM7/26/18
to Django users
Hi Experts,

I am facing a strange issue in my Django2.0.6+Mysql application.

In my settings ,py I have set Debug=True, but in logs I am not seeing any info/warning/error.

Currently I am merging two products into one to remove duplicate products from Django admin panel but when I click on Preview button page is just refreshed; no any error in logs.

So I need to investigate the cause but unable to find since not getting any logs.

Can anyone please tell me how can enable logs here?

Thanks!

Jason

unread,
Jul 26, 2018, 6:41:27 AM7/26/18
to Django users
sounds like you have a misconfiguration with your logging.  post your LOGGING dict in your settings

prateek gupta

unread,
Jul 26, 2018, 6:48:30 AM7/26/18
to Django users
PFB my settings-
# Reading data from the environment file
ENV_FILE_PATH = os.path.join(BASE_DIR, 'config.json')
try:
    with open(ENV_FILE_PATH) as env_file:
        ENV_TOKENS = json.load(env_file)
except IOError:
    logger = logging.getLogger(__name__)
    logger.warning('Couldn\'t find the env file! You running on '
                   'absolute dummy configurations.')
    ENV_TOKENS = {}

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Jason

unread,
Jul 26, 2018, 7:17:18 AM7/26/18
to Django users
ok, so you don't even have any logging configuration at all, no wonder you don't see anything.

I suggest you look in the docs for this:  https://docs.djangoproject.com/en/2.0/topics/logging/


prateek gupta

unread,
Jul 26, 2018, 7:46:19 AM7/26/18
to Django users
I forgot to mentions, I am using logger also as below-
# send server errors to admin
ADMINS = (('admin', 'admin@example.com'),)
MANAGERS
= ADMINS

# Logging configuration for production
LOGGING = {
   
'version': 1,
   
'disable_existing_loggers': False,
   
'formatters': {
       
'verbose': {
           
'format': '%(asctime)s [%(levelname)s] %(filename)s:%(lineno)s %(funcName)s() : %(message)s'
        },
       
'simple': {
           
'format': '%(asctime)s [%(levelname)s] : %(message)s'
        },
   
},
   
'handlers': {
       
'file': {
           
'level': 'ERROR',
           
'class': 'logging.FileHandler',
           
'filename': 'error.log',
           
'formatter': 'verbose'
        },
       
'mail_admins': {
           
'level': 'ERROR',
           
'class': 'django.utils.log.AdminEmailHandler',
           
'formatter': 'simple'
        },
   
},
   
'loggers': {
       
'django': {
           
'handlers': ['file'],
           
'level': 'ERROR',
           
'propagate': True,
       
},
       
'django.request': {
           
'handlers': ['mail_admins'],
           
'level': 'ERROR',
           
'propagate': True,
       
},
   
},
}

Jason

unread,
Jul 26, 2018, 8:36:16 AM7/26/18
to Django users
OK, that's helpful.  Your loggers are set to handle error and above, right?  So Django's blocked from doing any logging below that, even with DEBUG = True

prateek gupta

unread,
Jul 26, 2018, 8:42:17 AM7/26/18
to Django users
I tried with below one to include warning also but no any warning or error in logs-
LOGGING_CONFIG = None

LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()

logging
.config.dictConfig({

   
'version': 1,
   
'disable_existing_loggers': False,
   
'formatters': {

       
'default': {
           
# exact format is not important, this is the minimum information
            'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
       
},
       
'django.server': DEFAULT_LOGGING['formatters']['django.server'],
   
},
   
'handlers': {
       
# console logs to stderr
        'console': {
           
'class': 'logging.StreamHandler',
           
'formatter': 'default',
       
},
       
# Add Handler for Sentry for `warning` and above
        'sentry': {
           
'level': 'WARNING',
           
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
       
},
       
'django.server': DEFAULT_LOGGING['handlers']['django.server'],
   
},
   
'loggers': {
       
# default for all undefined Python modules
        '': {
           
'level': 'WARNING',
           
'handlers': ['console', 'sentry'],
       
},
       
# Our application code
        'app': {
           
'level': LOGLEVEL,
           
'handlers': ['console', 'sentry'],
           
# Avoid double logging because of root logger
            'propagate': False,
       
},
       
# Prevent noisy modules from logging to Sentry
        'noisy_module': {
           
'level': 'ERROR',
           
'handlers': ['console'],
           
'propagate': False,
       
},
       
# Default runserver request logging
        'django.server': DEFAULT_LOGGING['loggers']['django.server'],
   
},
})

Jason

unread,
Jul 26, 2018, 8:52:45 AM7/26/18
to Django users
You need to add the logging config to `LOGGING` in the settings for django to pick it up.   logging.config.dictConfig   doesn't do it.

prateek gupta

unread,
Jul 26, 2018, 9:31:26 AM7/26/18
to Django users
I have changes like below but does not have any affect-
import logging
# Disable Django's logging setup

Jason

unread,
Jul 26, 2018, 9:36:10 AM7/26/18
to Django users
no, I mean like this:

LOGGING = {

prateek gupta

unread,
Jul 26, 2018, 9:41:22 AM7/26/18
to Django users
then it says -
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\cms-app\ps-cms\ps_cms\settings.py", line 256, in <module>
    'django.server': DEFAULT_LOGGING['loggers']['django.server'],
TypeError: 'module' object is not callable

prateek gupta

unread,
Jul 26, 2018, 9:42:31 AM7/26/18
to Django users
I am using like below-
logging({
})

prateek gupta

unread,
Jul 26, 2018, 9:44:14 AM7/26/18
to Django users
If I use as yours then there is no any trace in logs.
Reply all
Reply to author
Forward
0 new messages