1

I have no idea why this is not working. Im using linode to host my ubuntu server with apache hosting my django.

in my settings.py file I have this to define my logger

 import logging

 LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
    'standard': {
            'format' : '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
    },
},

'handlers': {
    'default': {
        'level': 'DEBUG',
        'class': 'logging.handlers.RotatingFileHandler',
        'filename': '/logs/django.log',
        'maxBytes': 1024*1024*5,
        'formatter' : 'standard',
        'backupCount': 5,
    },
},
'loggers': {
    '': {
        'handlers': ['default'],
        'level': 'DEBUG',
        'propagate': True,
    },
},

}

then I use it in my view like this

   import logging
   logr = logging.getLogger(__name__)

   def login(request):
      logr.debug("THIS BETTER WORK >:O")
      c = {}
      c.update(csrf(request))
      return render_to_response('accounts/login.html', c)

I'm not getting any error messages or any output just nothing its not writing to file or anything.

What am I doing wrong? I created the log file put it in the right spot and gave it full permissions. I'm getting pretty desperate at this point. I just want any way to log something so I can start debugging my website.

3
  • Can u get the other error messages over apache? Maybe your apache configuration is wrong. Commented Feb 6, 2014 at 10:53
  • what is file permission for /logs/django.log ?? Commented Feb 6, 2014 at 10:57
  • Yea i get errors in appche log. File permission is 777 Commented Feb 6, 2014 at 17:17

2 Answers 2

1

I was stuck in the same issue once. What I found was a bit confusing to me, but it worked. The issue was with parameter

disable_existing_loggers: True,

Using this param to true, means you want to disable all the loggers and override it with existing django logger which you have defined. But, it does not do so automatically. You also need to redefine those loggers in the settings.py file and also their parents.

In my case, I did not have any such requirement. So rather than going from the pain of redefining all the logger I just changed the parameter and set it to false. And it worked.

disable_existing_loggers: False,

I hope this solves your issue. Permission checks can also be performed.

Additionaly, you can user Sentry to trace what is wrong with your code.

Sign up to request clarification or add additional context in comments.

3 Comments

It didn't work :/ Where does the file name start at? Is it dirOfSettingsFile/logs/django.log ? or is it basedir/logs/django.log
I think the problem is with your configuration. You have used: 'filename': '/logs/django.log', Now what Django will look for here is "logs" directory under "/", and then will create a file inside the directory. So, in case of permission issues or directory not present, file will not be created and you will observe nothing. To fix this, either create a "logs" directory inside your "/" directory. Please note this will fail, in case you run it in Windows machine.
A better approach will be to use "filename': 'logs/django.log' param and create logs directory under the same directory where settings.py reside.
1

I am couple of years late but anyways i faced similar issue and below is my comment

'filename': '/logs/django.log',

to

'filename': '/fillpath/logs/django.log',
or
BASE_DIR = 'django project path'
'filename': os.path.join(BASE_DIR, 'logs/django.log'),

Also in the views or wherever you want to log things

Below one works with django runserver but not with apache httpd

import logging
logme = logging.getLogger('__name__')

Make below change and it will work for apache/httpd

import logging
logme = logging.getLogger('seekers')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.