跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教, log 如何命名分割业务?
未分類
15 5 月 2020

请教, log 如何命名分割业务?

请教, 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)

  • 資深大佬 : jones2000

    日志这个东西怎么说呢, 应该是越详细越好,但是打的多了会降低性能,你要把日志成分多个等级的,如果调试日志,模块日志, 错误日志 等等要细分, 通过接口就可以动态控制打印哪些等级或哪些模块的日志。
    我一般使用的日志格式: 日期 ,时间, 进程 id, 线程 id, 日志等级, 文件名,行号, 类名, 函数名 , 具体的日志输出信息。
    日志信息文件可以是 1 个小时生成 1 个日志文件或 1 天生成 1 个日志文件,具体看日志量了。 后面就是对接日志收集+日志分析系统,开源的很多随便找一个就可以,然后定期清理日志文件比如保留最近 1 个月或 1 个星期

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具