请教, log 如何命名分割业务?
資深大佬 : chaleaoch 3
level 啊, RotatingFileHandler, 时间戳啊, 这些都还不是问题. 在哪里打 log, 打多打少,这方面虽然还不是很成熟,但也不是问题的关键.
django 官网是这么说的.
By convention, the logger name is usually __name__, the name of the Python module that contains the logger. This allows you to filter and handle logging calls on a per-module basis. However, if you have some other way of organizing your logging messages, you can provide any dot-separated name to identify your logger:
# Get an instance of a specific named logger logger = logging.getLogger('project.interesting.stuff')
我用起来不是很习惯, 当然目前项目的代码结构有问题,也是导致__name__的方式不好用的原因之一.
除了这种方式, 现在不是很清楚, 是否还有其他最佳实践可以分享给主, logger 要分多少个? 怎么分?
谢谢了
其实就是想看一下大家的这个东西.
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '[%(process)d] [%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s' } }, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'maxBytes': 1024*1024, 'backupCount': 5, 'filename': '/tmp/run.log', 'formatter': 'verbose' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose' } }, 'loggers': { 'django_docker': { 'handlers': ['file', 'console'], 'level': 'DEBUG', 'propagate': True, }, 'django.request': { 'handlers': ['file'], 'level': 'ERROR', 'propagate': False, } }, }
大佬有話說 (1)