I'm trying to write to a logger in Django. I've got at the beginning of the views.py
file:
我想给Django的一个日志记录程序写封信。我在视图的开头。py文件:
import logging
logger = logging.getLogger('wm')
and later make calls to
然后打电话
logger.debug('message')
In my settings.py
file, I have defined
在我的设置。py文件,我已经定义了。
LOGGING = {
'formatters': {
'medium': {
'format': '[%(username)s] %(levelname)s %(asctime)s: %(message)s'
}
},
'handlers': {
'wmlogfile': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/var/log/django/wm.log',
'level':'DEBUG',
'maxBytes': 1024*1024, # 5 MB
'backupCount': 5,
'formatter': 'medium',
},
},
'loggers': {
'wm': {
'handlers': ['wmlogfile'],
'level': 'DEBUG',
'propagate': False,
}
}
}
At first, I was getting 500 errors because the file didn't exist, and then because the permission was denied. I manually created the file and set the permissions to 777, and the app runs, but I get no output in the log file.
起初,我有500个错误,因为文件不存在,然后因为权限被拒绝。我手动创建了文件并将权限设置为777,应用程序运行,但日志文件中没有输出。
What have I done wrong?
我做错了什么?
1 个解决方案
#1
1
Try setting disable_existing_loggers
to False
as per the example here.
尝试按照这里的示例将disable_existing_loggers设置为False。
#1
1
Try setting disable_existing_loggers
to False
as per the example here.
尝试按照这里的示例将disable_existing_loggers设置为False。