Django Log to File

xster
xster
Published in
1 min readMay 9, 2011

In the official Django logging docs, it wasn’t very clear about how to log to files. As you can understand, Django can use any Python logging classes that are all listed here. One of them is FileHandler. To use it, just add this to your settings.py

LOGGING = {
...
'handlers': {
...
'file':{
'level': 'DEBUG',
'class': 'logging.FileHandler',
}
},
...
}

But the FileHandler class constructor needs more parameters. To add them, you have to add the parameter name key with its value into the dictionary.

LOGGING = {
...
'handlers': {
...
'file':{
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'debug.log',
}
},
...
}

--

--