• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于python:Dblogger一个Python语言实现支持多进程和多线程日志打印高效Python日志库

python 搞代码 4年前 (2022-02-20) 17次浏览 已收录 0个评论
日期 作者 版本 备注
2020-12-7 dingbin v1.0

Dblogger: a powerful Python library supporting multi process and multi thread printing logs

Dblogger project implements a both multi-threads-safe and multi-process-safe logger library named dblogger in python language. It works well and has stable function and powerful performance,especially in multithreaded or multiprocessed Python programs.

Main interfaces of dblogger are implemented in file: smartlogger/utils.dblogger.py .

dblogger configuration file is: smartlogger/conf/logger.conf.

The dblogger configuration file has the following format:

[loggers]
keys=root,SafeLogger

[handlers]
keys=consoleHandler,fileHandler,rotatingFileHandler,timedRotatingFileHandler,truncateTimedRotatingFileHandler

[formatters]
keys=fmt0

[logger_root]
level=INFO
handlers=consoleHandler

[logger_SafeLogger]
level=INFO
#handlers=consoleHandler,truncateTimedRotatingFileHandler
handlers=truncateTimedRotatingFileHandler
qualname=SafeLogger
propagate=0

[handler_consoleHandler]
class=StreamHandler
args=(sys.stdout,)
level=INFO
formatter=fmt0

[handler_fileHandler]
class=FileHandler
args=("logs/app.log", "a")
level=INFO
formatter=fmt0

[handler_rotatingFileHandler]
class=handlers.RotatingFileHandler
args=("logs/app.log", 'a',100*1024*1024, 100)
level=INFO
formatter=fmt0


[handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
args=("logs/app.log", 'm', 1, 3600)
level=INFO
formatter=fmt0

[handler_truncateTimedRotatingFileHandler]
class=smartlogger.utils.logutils.truncate_timed_rotating_filehandler.TruncateTimedRotatingFileHandler
args=("logs/app.log", 'm', 1, 3600)
level=INFO
formatter=fmt0



[formatter_fmt0]
format=[%(asctime)s] [%(msecs)d,process(%(process)d),thread(%(thread)d),%(filename)s:%(lineno)d -- %(funcName)s() %(levelname)s] [%(message)s]
datefmt=%Y-%m-%d %H:%M:%S

TruncateTimedRotatingFileHandler was so important that it implements the following features: every few minutes or hours, it generates the log file name with a specific meaning, and then outputs the log content to the log file with the corresponding name. It was a truncated time rotating file handler and it’s so useful.

You can run dblogger demo examples like this:

python -m smartlogger.loggerdemo.simpleloggerdemo
python -m smartlogger.utils.logutils.dbloggerdemo

Then you will see the rotating log files generated under directory: smartlogger/logs after run above demo commands. And the log file names may be like: app.log and app.log.2020-11-08_01-01 and so on.

See GitHub address: https://github.com/apollo008/dblogger for source code and details.


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于python:Dblogger一个Python语言实现支持多进程和多线程日志打印高效Python日志库

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址