支持按时间滚动的Python多进程日志Handler
Project description
MultProcTimedRotatingFileHandler
支持按时间滚动的Python多进程日志Handler, 支支持macOS/Linux, 自用未充分测试
参考了 https://github.com/yorks/mpfhandler, 有如下优化
- 添加了intervel支持
- 支持备份自动清理
- 使用MMAP优化了性能
性能基准
8核CPU, 8进程, 100000条长度47字符日志测试, 相比TimedRotatingFileHandler大约有25%-30%性能损耗
随着进程数增大, 锁竞争也变激烈了, 性能损耗也会进一步增大, 100进程下会有50%-60%性能损耗
8进程, QPS情况
- MultProcTimedRotatingFileHandler: 23482
- TimedRotatingFileHandler: 30349
配置示例
import logging.config
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '[%(levelname)s %(asctime)s %(name)s %(lineno)d %(process)d %(thread)d] %(message)s'
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'backend_file':{
'class': 'mptrfhandler.MultProcTimedRotatingFileHandler',
'filename': 'main.log',
'when': 'H', # 按小时滚动
'backupCount': 10, #备份份数
'formatter':'verbose', #使用哪种formatters日志格式
'level': 'DEBUG',
'delay': True,
},
},
'loggers': {
'': {
'handlers': ['backend_file'],
'level': "INFO",
'propagate': False,
},
},
}
logging.config.dictConfig(LOGGING_CONFIG)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mptrfhandler-0.0.8.tar.gz
(8.1 kB
view details)
File details
Details for the file mptrfhandler-0.0.8.tar.gz
.
File metadata
- Download URL: mptrfhandler-0.0.8.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91af9cdf90e5b9ac5fb6bdad817bed7b5590f0bff404a220be796a4b47672b4f |
|
MD5 | 6207cd847b5665da2dc572389918d708 |
|
BLAKE2b-256 | dad9ad2b154aaa3e8ab0e00a05b035cc5e028c665a39117eb8324078d5b02b08 |