python日志按我的方式做
stdlogpj的Python项目详细描述
stdlogpj公司
python日志按我的方式做
主页:https://github.com/prjemian/stdlogpj
安装
pip install stdlogpj
用法:
^{pr2}$演示:
#!/usr/bin/env pythonimportstdlogpjlogger=stdlogpj.standard_logging_setup("stdlogpj-demo")defthing1(i):logger.info(f"something #{i+1}")defmain():logger.info("hello")foriinrange(5):logger.debug("calling thing1()")thing1(i)logger.critical("complete")if__name__=="__main__":logger.warning("before main()")main()logger.error("after main(): no error, really")
旋转文件并限制大小
使用RotatingFileHandler的特性, 可以通过切换到新的日志文件来限制文件的大小, 通过追加一个数字来保存旧的日志文件。较低的数字是最近才出现的。
使用此选项可将日志限制为1 MB,且不超过5个编号(以前的)日志文件:
logger = stdlogpj.standard_logging_setup("stdlogpj-demo", maxBytes=1024*1024, backupCount=5)
- 项目
标签: