My goal is to create a "log" application, in addition to my main application, which will be used for several custom classes of handlers, filters, etc. and other bug reports and statistics. But when I start the dev server for my Django project, I get an error:
File "/Library/Python/2.7/site-packages/Django-1.3-py2.7.egg/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/Django-1.3-py2.7.egg/django/conf/__init__.py", line 139, in __init__
logging_config_func(self.LOGGING)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 776, in dictConfig
dictConfigClass(config).configure()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 575, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'db_handler': Unable to configure handler 'db_handler': 'module' object has no attribute 'models'
My LOGGING directive in the settings looks like this:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s::(%(process)d %(thread)d)::%(module)s - %(message)s'
},
},
'handlers': {
'db_handler': {
'level': 'DEBUG',
'class': 'Project.log.handlers.db_handler'
},
'file_handler': {
'level': 'DEBUG',
'formatter':'default',
'class': 'logging.TimedRotatingFileHandler',
'filename':'Custom_log',
'when':'midnight',
'interval':1
},
},
'loggers': {
'django.request': {
'handlers': ['db_handler'],
'level': 'DEBUG',
'propagate': True,
},
}
}
The layout of my "log" application is pretty simple nowadays:
log/
__init__.py
handlers.py
models.py
models.py contains one model, LogHandler:
from django.db import models
class LogRecord(models.Model):
....
....
and handlers.py contains one handler:
import logging
from models import LogRecord
class db_handler(logging.Handler):
def emit(self, record):
....
....
, , , LogRecord. project.log.models log.models, . models.py , , , "" "".
__ init __.py.