LogCollectionFormatter2
介绍
LogCollectionFormatter2 是一个灵活的日志记录和消息队列工具库,专为 Python 应用程序设计。它提供了强大的日志记录和消息队列功能,帮助开发者轻松追踪应用程序的运行状态和发送日志消息到消息队列中。
安装
可以通过 pip 安装 LogCollectionFormatter2:
pip install LogCollectionFormatter2
主要组件
BaseLog 类
BaseLog 是所有日志功能的基类,提供基本的日志配置和日志记录方法。主要功能包括:
- 配置日志级别、日志文件名、日志文件路径等。
- 支持日志文件的自动轮转。
- 提供多种日志级别的方法,如
debug,info,warn,error等。 - 支持自定义日志格式和扩展日志记录功能。
MainLog 类
MainLog 继承自 BaseLog,增加了对消息队列的支持。主要功能包括:
- 配置消息队列(如 RabbitMQ)的连接参数。
- 提供将日志消息发送到消息队列的功能。
- 支持装饰器模式,方便在 Flask 或其他 Web 框架中自动记录接口访问日志。
InsertQueue 类
InsertQueue 类负责管理消息队列的连接和消息发送。主要功能包括:
- 管理和维护消息队列的连接池。
- 提供同步和异步发送消息到消息队列的方法。
- 支持连接的重试和异常处理。
使用示例
基本日志记录
from LogCollectionFormatter2 import MainLog
# 初始化 MainLog 实例
log = MainLog(app_name='MyApp', prefix_path='/var/log/myapp', t_code='10001')
# 记录不同级别的日志
log.debug('This is a debug message')
log.info('This is an info message')
log.warn('This is a warning message')
log.error('This is an error message')
集成 Flask 和消息队列
from flask import Flask, request, jsonify
from LogCollectionFormatter2 import MainLog
app = Flask(__name__)
# 初始化日志记录器和消息队列支持
log = MainLog(
app_name='FlaskApp', prefix_path='/var/log/flaskapp', t_code='10002',
journal_mq_enable=True, host='rabbitmq_host', port=5672
)
@app.route('/api/data', methods=['POST'])
@log.with_internal_journallog(method_code='GET_DATA')
def get_data():
data = request.json
# 处理数据...
return jsonify({'status': 'success', 'data': data})
if __name__ == '__main__':
app.run(debug=True)
配置参数
MainLog 初始化时支持多种配置参数,以便灵活适应不同的应用场景。主要参数包括:
app_name: 应用名称,用于日志文件的命名。prefix_path: 日志文件存储的前缀路径。t_code: 交易代码,用于日志记录中的特定标识。journal_log_enable: 是否启用日志记录功能。journal_mq_enable: 是否启用消息队列功能。host,port,virtual_host,name,password: RabbitMQ 连接参数。
更多配置参数请参考源代码中的 MainLog 类定义。
注意事项
- 确保 RabbitMQ 或其他消息队列服务正常运行。
- 在生产环境中,建议关闭 Flask 的
debug模式以提高性能和安全性。 - 根据实际应用场景调整日志级别和文件轮转策略。
联系我们
如果您在使用过程中遇到任何问题或有任何建议,请通过 GitHub Issues 反馈给我们。
许可证
LogCollectionFormatter2 遵循 BSD 3-Clause 许可证。详细信息请参考 LICENSE 文件。
Metadata
Release files for LogCollectionFormatter2 2.0.3
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 | |
|---|---|---|---|---|
| logcollectionformatter2-2.0.3.tar.gz | 10.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| LogCollectionFormatter2-2.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.9 kB
Release files / logcollectionformatter2-2.0.3.tar.gz
| Download URL | logcollectionformatter2-2.0.3.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f70373b160ce6315e85d64285dc0c28964690d873f5bed13dbbbd939ba827d32
|
|
BLAKE2b-256 checksum How to use checksums |
ed79237201e65fa72b7a6476e6d4f6717165a8ffd3969231293d3ef1f2cfa606
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / LogCollectionFormatter2-2.0.3-py3-none-any.whl
| Download URL | LogCollectionFormatter2-2.0.3-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c20b8bec6de45d7915fad5b3ec0cd631f61d54c2d90d4151f2aadd7d38d56dd1
|
|
BLAKE2b-256 checksum How to use checksums |
7cf4012747a16a0228d27bef6746b7e9ebccbcc2a27172d2f41bfe88346245ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for LogCollectionFormatter2 2.0.3
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.