在django项目中生成此日志文件结构所需的建议 [英] Suggestions required for generating this logging file structure in django project

查看:98
本文介绍了在django项目中生成此日志文件结构所需的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议如何使用django项目中的python日志生成具有以下目录文件结构的日志文件。

  logs / 2009-03-09 
/errors.log
/warnings.log
/info.log
/emails.log
/messages.log

logs / 2009-03-08
/errors.log
/ warnings .log
/info.log
/emails.log
/messages.log


FileHandler 具有的过滤器的解决方案

    c $ c>实例匹配这些文件的条件。
  1. 将处理程序添加到根记录器。

  2. 利润; - )

请参阅此另一个答案是一个匹配特定级别的过滤器的示例。您可以使用它来为电子邮件和消息日志创建自己的自定义过滤器。



使用 strftime 格式化带有日期的路径。


Can anyone please suggest how to generate log files having following directory-file structure using python logging in django project.

logs/2009-03-09 
          /errors.log
          /warnings.log
          /info.log
          /emails.log
          /messages.log

logs/2009-03-08 
          /errors.log
          /warnings.log
          /info.log
          /emails.log
          /messages.log

解决方案

  1. Set up FileHandler instances with Filter instances which match the criteria for those files.
  2. Add the handlers to the root logger.
  3. Profit ;-)

See this other answer for an example of a filter which matches a specific level. You can use that as an example to create your own custom filters for 'emails' and 'messages' logs.

Use strftime to format the paths with dates in them.

这篇关于在django项目中生成此日志文件结构所需的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆