3

I've added the following to my settings.py file:

import logging
...
logging.basicConfig(level=logging.DEBUG,
    format='%(asctime)s %(levelname)s %(message)s',
    filename=os.path.join(rootdir, 'django.log'),
    filemode='a+')

And in views.py, I've added:

import logging
log = logging.getLogger(__name__)
...
log.info("testing 123!")

Unfortunately, no log file is being created. Any ideas what I am doing wrong? And also is their a better method I should be using for logging? I am doing this on Webfaction.

FunLovinCoder
  • 7,597
  • 11
  • 46
  • 57

1 Answers1

2

Python logging for Django is fine on somewhere like Webfaction. If you were on a cloud-based provider (eg Amazon EC2) where you had a number of servers, it might be worth looking at either logging to key-value DB or using Python logging over the network.

Your logging setup code in settings.py looks fine, but I'd check that you can write to rootdir -- your syslog might show errors, but it's more likely that Django would be throwing a 500 if it couldn't log properly.

Which leads me to note that the only major difference in my logging (also on WebFaction) is that I do:

import logging
logging.info("Something here") 

instead of log.info

Steve Jalim
  • 11,989
  • 1
  • 37
  • 54
  • Don't know why, but changing to logging.info did the trick. Thanks. – FunLovinCoder May 16 '10 at 12:47
  • Seems like the original `log.info()` should have worked, because you (@FunLovinCoder) started a new instance of a logger with `log = logging.getLogger(__name__)`. Mine works fine and it's the same... – nicorellius Jan 04 '14 at 15:56