python多线程logger_python多线程logger_Dblogger:一个Python语言实现支持多进程和多线程日志打印高效Python日志库......

日期作者版本备注2020-12-7dingbinv1.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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值