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)
Metadata
Release files for mptrfhandler 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mptrfhandler-0.0.8.tar.gz | 8.1 kB | Without provenance | Details |
Release files / mptrfhandler-0.0.8.tar.gz
| Download URL | mptrfhandler-0.0.8.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91af9cdf90e5b9ac5fb6bdad817bed7b5590f0bff404a220be796a4b47672b4f
|
|
BLAKE2b-256 checksum How to use checksums |
dad9ad2b154aaa3e8ab0e00a05b035cc5e028c665a39117eb8324078d5b02b08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for mptrfhandler 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.