## 1 kuai_log
安装 pip install kuai_log
kuai_log 是最快的python日志,比loguru和logging快30倍.
kuai_log的控制台日志自动彩色.
kuai_log的文件日志多进程切割安全.
kuai_log的文件日志支持更友好的json文件写入,更适合elk采集.(例如logger.info直接记录一个字典,会自动转换)
kuai_log KuaiLogger 对象的方法名和入参在logging.Logger对象中一定存在,且参数相同,虽然不是基于logging开发,但保持了良好的兼容性
### 1.2 为什么用 kuai_log
```
用户怕了logging包的创建logger, 创建handler, handler设置formatter, logger添加handler 的方式,感觉logging复杂,导致用户想用loguru
loguru对logging包的不兼容和复杂.比如loguru记录flask框架的已有日志内容,就比较麻烦,说的是在已有logging命名空间添加handler,loguru困难.
例如loguru记录flask werkzeug 请求记录的日志 ,记录 tornado.access的 日志,麻烦.
```
## 2 性能比较
在 win11 + r7 4800h上,
单进程for for循环写入10万次控制台和文件,(具体的测试代码可以直接用 tests/compare_spped 中的代码验证)
```
loguru 写入文件和打印控制台,10万次日志耗费48秒
logging 写入文件和打印控制台,10万次日志耗费45秒
nb_log 写入文件和打印控制台,10万次日志耗费7秒
kuai_log 写入文件和打印控制台,10万次日志耗费1.7秒
```
## 3 kuai_log 写入 10万次文件和打印控制台代码:
```python
import logging
import time
from kuai_log import get_logger
logger = get_logger(name='test', level=logging.DEBUG, log_filename='t5.log',
log_path='/pythonlogs', is_add_file_handler=True,
)
t_start = time.time()
for i in range(10):
logger.debug(i)
print(time.time() - t_start)
```
### 3.2 kuai_log的日志级别和常用的日志是一样的.debug info warning error critical
```python
import logging
import time
from kuai_log import get_logger
logger = get_logger(name='test77', level=logging.DEBUG, log_filename='t777.log',
log_path='/pythonlogs', is_add_file_handler=True,
json_log_path='/python_logs_json', is_add_json_file_handler=True,
)
t_start = time.time()
for i in range(1):
logger.debug(i)
logger.info(i)
logger.warning(i)
logger.error(i)
logger.critical(i)
print(time.time() - t_start)
```
## 4 kuai_log 用法比logging和loguru简单.
### 4.1 有些人问需要实例化生成logger,没有 from loguru import logger直接用爽?
```
因为是每个name的日志行为是独立的,用户在大项目中有很多个日志,不同的表现行为不同,
例如有的函数里面日志界别高才输出,有的模块需要日志级别低就输出,
例如有的模块的日志需要写入文件,有的模块的日志不需要写入文件,
所以用不同的name来区分日志是最好的
```
### 4.2 用户想偷懒,学习loguru直接导入就使用,想不需要手动实例化生成logger
kuai_log 自带一个已经实例化好的 k_logger 对象,你还嫌麻烦?
```python
from kuai_log import k_logger
k_logger.debug('hello')
```
## 5 kuai_log为什么快?
因为logging日志系统功能非常丰富强大,扩展性好,代码较为复杂,kuai_log没有基于logging包来封装,是完全从0写的,代码简单自然就性能好了.
kuai_log实现的文件日志多进程rotate切割安全,使用了特殊的方式,所以技能保证切割不报错又能保证性能.
nb_log是基于logging封装的,kuai_log是手写的.
## 6 kuai_log 日志截图
![ackrX.png](https://img.vinua.cn/images/ackrX.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/ydf0509/kuai_log",
"name": "kuai-log",
"maintainer": "ydf",
"docs_url": null,
"requires_python": "",
"maintainer_email": "ydf0509@sohu.com",
"keywords": "logging,log,logger,loguru,nb_log,rotate file",
"author": "bfzs",
"author_email": "ydf0509@sohu.com",
"download_url": "https://files.pythonhosted.org/packages/3e/0b/134328c0b3c238acf39100156c6e894d8ecfe8c4776f46102ebac19c2730/kuai_log-0.8.tar.gz",
"platform": "all",
"description": "## 1 kuai_log\r\n\r\n\u5b89\u88c5 pip install kuai_log\r\n\r\nkuai_log \u662f\u6700\u5feb\u7684python\u65e5\u5fd7,\u6bd4loguru\u548clogging\u5feb30\u500d.\r\n\r\nkuai_log\u7684\u63a7\u5236\u53f0\u65e5\u5fd7\u81ea\u52a8\u5f69\u8272.\r\n\r\nkuai_log\u7684\u6587\u4ef6\u65e5\u5fd7\u591a\u8fdb\u7a0b\u5207\u5272\u5b89\u5168.\r\n\r\nkuai_log\u7684\u6587\u4ef6\u65e5\u5fd7\u652f\u6301\u66f4\u53cb\u597d\u7684json\u6587\u4ef6\u5199\u5165,\u66f4\u9002\u5408elk\u91c7\u96c6.(\u4f8b\u5982logger.info\u76f4\u63a5\u8bb0\u5f55\u4e00\u4e2a\u5b57\u5178,\u4f1a\u81ea\u52a8\u8f6c\u6362)\r\n\r\nkuai_log KuaiLogger \u5bf9\u8c61\u7684\u65b9\u6cd5\u540d\u548c\u5165\u53c2\u5728logging.Logger\u5bf9\u8c61\u4e2d\u4e00\u5b9a\u5b58\u5728,\u4e14\u53c2\u6570\u76f8\u540c,\u867d\u7136\u4e0d\u662f\u57fa\u4e8elogging\u5f00\u53d1,\u4f46\u4fdd\u6301\u4e86\u826f\u597d\u7684\u517c\u5bb9\u6027\r\n\r\n### 1.2 \u4e3a\u4ec0\u4e48\u7528 kuai_log\r\n\r\n```\r\n\u7528\u6237\u6015\u4e86logging\u5305\u7684\u521b\u5efalogger, \u521b\u5efahandler, handler\u8bbe\u7f6eformatter, logger\u6dfb\u52a0handler \u7684\u65b9\u5f0f,\u611f\u89c9logging\u590d\u6742,\u5bfc\u81f4\u7528\u6237\u60f3\u7528loguru\r\n\r\nloguru\u5bf9logging\u5305\u7684\u4e0d\u517c\u5bb9\u548c\u590d\u6742.\u6bd4\u5982loguru\u8bb0\u5f55flask\u6846\u67b6\u7684\u5df2\u6709\u65e5\u5fd7\u5185\u5bb9,\u5c31\u6bd4\u8f83\u9ebb\u70e6,\u8bf4\u7684\u662f\u5728\u5df2\u6709logging\u547d\u540d\u7a7a\u95f4\u6dfb\u52a0handler,loguru\u56f0\u96be.\r\n\u4f8b\u5982loguru\u8bb0\u5f55flask werkzeug \u8bf7\u6c42\u8bb0\u5f55\u7684\u65e5\u5fd7 ,\u8bb0\u5f55 tornado.access\u7684 \u65e5\u5fd7,\u9ebb\u70e6.\r\n\r\n```\r\n\r\n## 2 \u6027\u80fd\u6bd4\u8f83\r\n\r\n\u5728 win11 + r7 4800h\u4e0a,\r\n\r\n\u5355\u8fdb\u7a0bfor for\u5faa\u73af\u5199\u516510\u4e07\u6b21\u63a7\u5236\u53f0\u548c\u6587\u4ef6\uff0c\uff08\u5177\u4f53\u7684\u6d4b\u8bd5\u4ee3\u7801\u53ef\u4ee5\u76f4\u63a5\u7528 tests/compare_spped \u4e2d\u7684\u4ee3\u7801\u9a8c\u8bc1\uff09\r\n\r\n```\r\nloguru \u5199\u5165\u6587\u4ef6\u548c\u6253\u5370\u63a7\u5236\u53f0,10\u4e07\u6b21\u65e5\u5fd7\u8017\u8d3948\u79d2\r\n\r\nlogging \u5199\u5165\u6587\u4ef6\u548c\u6253\u5370\u63a7\u5236\u53f0,10\u4e07\u6b21\u65e5\u5fd7\u8017\u8d3945\u79d2\r\n\r\nnb_log \u5199\u5165\u6587\u4ef6\u548c\u6253\u5370\u63a7\u5236\u53f0,10\u4e07\u6b21\u65e5\u5fd7\u8017\u8d397\u79d2\r\n\r\nkuai_log \u5199\u5165\u6587\u4ef6\u548c\u6253\u5370\u63a7\u5236\u53f0,10\u4e07\u6b21\u65e5\u5fd7\u8017\u8d391.7\u79d2\r\n```\r\n\r\n## 3 kuai_log \u5199\u5165 10\u4e07\u6b21\u6587\u4ef6\u548c\u6253\u5370\u63a7\u5236\u53f0\u4ee3\u7801:\r\n\r\n```python\r\nimport logging\r\nimport time\r\n\r\nfrom kuai_log import get_logger\r\n\r\nlogger = get_logger(name='test', level=logging.DEBUG, log_filename='t5.log',\r\n log_path='/pythonlogs', is_add_file_handler=True,\r\n )\r\n\r\nt_start = time.time()\r\nfor i in range(10):\r\n logger.debug(i)\r\nprint(time.time() - t_start)\r\n```\r\n\r\n### 3.2 kuai_log\u7684\u65e5\u5fd7\u7ea7\u522b\u548c\u5e38\u7528\u7684\u65e5\u5fd7\u662f\u4e00\u6837\u7684.debug info warning error critical \r\n\r\n```python\r\nimport logging\r\nimport time\r\n\r\nfrom kuai_log import get_logger\r\n\r\nlogger = get_logger(name='test77', level=logging.DEBUG, log_filename='t777.log',\r\n log_path='/pythonlogs', is_add_file_handler=True,\r\n json_log_path='/python_logs_json', is_add_json_file_handler=True,\r\n )\r\n\r\nt_start = time.time()\r\nfor i in range(1):\r\n logger.debug(i)\r\n logger.info(i)\r\n logger.warning(i)\r\n logger.error(i)\r\n logger.critical(i)\r\n\r\nprint(time.time() - t_start)\r\n```\r\n\r\n## 4 kuai_log \u7528\u6cd5\u6bd4logging\u548cloguru\u7b80\u5355.\r\n\r\n### 4.1 \u6709\u4e9b\u4eba\u95ee\u9700\u8981\u5b9e\u4f8b\u5316\u751f\u6210logger,\u6ca1\u6709 from loguru import logger\u76f4\u63a5\u7528\u723d?\r\n\r\n```\r\n\u56e0\u4e3a\u662f\u6bcf\u4e2aname\u7684\u65e5\u5fd7\u884c\u4e3a\u662f\u72ec\u7acb\u7684,\u7528\u6237\u5728\u5927\u9879\u76ee\u4e2d\u6709\u5f88\u591a\u4e2a\u65e5\u5fd7,\u4e0d\u540c\u7684\u8868\u73b0\u884c\u4e3a\u4e0d\u540c,\r\n\u4f8b\u5982\u6709\u7684\u51fd\u6570\u91cc\u9762\u65e5\u5fd7\u754c\u522b\u9ad8\u624d\u8f93\u51fa,\u6709\u7684\u6a21\u5757\u9700\u8981\u65e5\u5fd7\u7ea7\u522b\u4f4e\u5c31\u8f93\u51fa,\r\n\u4f8b\u5982\u6709\u7684\u6a21\u5757\u7684\u65e5\u5fd7\u9700\u8981\u5199\u5165\u6587\u4ef6,\u6709\u7684\u6a21\u5757\u7684\u65e5\u5fd7\u4e0d\u9700\u8981\u5199\u5165\u6587\u4ef6,\r\n\u6240\u4ee5\u7528\u4e0d\u540c\u7684name\u6765\u533a\u5206\u65e5\u5fd7\u662f\u6700\u597d\u7684\r\n```\r\n\r\n### 4.2 \u7528\u6237\u60f3\u5077\u61d2,\u5b66\u4e60loguru\u76f4\u63a5\u5bfc\u5165\u5c31\u4f7f\u7528,\u60f3\u4e0d\u9700\u8981\u624b\u52a8\u5b9e\u4f8b\u5316\u751f\u6210logger\r\n\r\nkuai_log \u81ea\u5e26\u4e00\u4e2a\u5df2\u7ecf\u5b9e\u4f8b\u5316\u597d\u7684 k_logger \u5bf9\u8c61,\u4f60\u8fd8\u5acc\u9ebb\u70e6?\r\n\r\n```python\r\nfrom kuai_log import k_logger\r\n\r\nk_logger.debug('hello')\r\n```\r\n\r\n## 5 kuai_log\u4e3a\u4ec0\u4e48\u5feb?\r\n\r\n\u56e0\u4e3alogging\u65e5\u5fd7\u7cfb\u7edf\u529f\u80fd\u975e\u5e38\u4e30\u5bcc\u5f3a\u5927,\u6269\u5c55\u6027\u597d,\u4ee3\u7801\u8f83\u4e3a\u590d\u6742,kuai_log\u6ca1\u6709\u57fa\u4e8elogging\u5305\u6765\u5c01\u88c5,\u662f\u5b8c\u5168\u4ece0\u5199\u7684,\u4ee3\u7801\u7b80\u5355\u81ea\u7136\u5c31\u6027\u80fd\u597d\u4e86.\r\n\r\nkuai_log\u5b9e\u73b0\u7684\u6587\u4ef6\u65e5\u5fd7\u591a\u8fdb\u7a0brotate\u5207\u5272\u5b89\u5168,\u4f7f\u7528\u4e86\u7279\u6b8a\u7684\u65b9\u5f0f,\u6240\u4ee5\u6280\u80fd\u4fdd\u8bc1\u5207\u5272\u4e0d\u62a5\u9519\u53c8\u80fd\u4fdd\u8bc1\u6027\u80fd.\r\n\r\nnb_log\u662f\u57fa\u4e8elogging\u5c01\u88c5\u7684,kuai_log\u662f\u624b\u5199\u7684.\r\n\r\n## 6 kuai_log \u65e5\u5fd7\u622a\u56fe\r\n\r\n![ackrX.png](https://img.vinua.cn/images/ackrX.png)\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "BSD License",
"summary": "kuai_log is most fast python log",
"version": "0.8",
"project_urls": {
"Homepage": "https://github.com/ydf0509/kuai_log"
},
"split_keywords": [
"logging",
"log",
"logger",
"loguru",
"nb_log",
"rotate file"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3e0b134328c0b3c238acf39100156c6e894d8ecfe8c4776f46102ebac19c2730",
"md5": "90c5b1b293b7afba3d8bf8b6d0165874",
"sha256": "f152cc4de75a6468da7acc4622259989b5751342716e42027acca5787c835f67"
},
"downloads": -1,
"filename": "kuai_log-0.8.tar.gz",
"has_sig": false,
"md5_digest": "90c5b1b293b7afba3d8bf8b6d0165874",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10913,
"upload_time": "2023-09-25T00:44:21",
"upload_time_iso_8601": "2023-09-25T00:44:21.422252Z",
"url": "https://files.pythonhosted.org/packages/3e/0b/134328c0b3c238acf39100156c6e894d8ecfe8c4776f46102ebac19c2730/kuai_log-0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-25 00:44:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ydf0509",
"github_project": "kuai_log",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "kuai-log"
}