## 1 fast_log
安装 pip install fast_log_nb
#### 记住安装是 pip install fast_log_nb ,使用是 import fast_log , 因为 fast_log 名字已经被人占用了
fast_log 是最快的python日志,比loguru和logging快30倍.
fast_log的控制台日志自动彩色.
fast_log的文件日志多进程切割安全.
fast_log的文件日志支持更友好的json文件写入,更适合elk采集.(例如logger.info直接记录一个字典,会自动转换)
### 1.2 为什么用 fast_log
```
内置的logging功能十分丰富强大扩展性好,但很多人不懂他的丰富功能,所以平时也没用到那些功能.
例如logging 树形的命名空间name,用户都不知道
用户只是简单的使用,那就可以不需要logging包了
```
## 2 性能比较
在 win11 + r7 4800h上
```
loguru 写入文件和打印控制台,10万次日志耗费48秒
logging 写入文件和打印控制台,10万次日志耗费45秒
nb_log 写入文件和打印控制台,10万次日志耗费7秒
fast_log 写入文件和打印控制台,10万次日志耗费1.7秒
```
## 3 fast_log 写入 10万次文件和打印控制台代码:
```python
import logging
import time
from fast_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 fast_log的日志级别和常用的日志是一样的.
```python
import logging
import time
from fast_log.logger 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 fast_log 用法比logging和loguru简单.
### 4.1 有些人问需要实例化生成logger,没有 from loguru import logger直接用爽?
```
用户是每个name的日志行为是独立的,所以用户在大项目中有很多个日志,不同的表现行为,
例如有的函数里面日志界别高才输出,有的模块需要日志级别低就输出,
例如有的模块的日志需要写入文件,有的模块的日志不需要写入文件,
所以用不同的name来区分日志是最好的
```
### 4.2 用户想偷懒,学习loguru直接导入就使用,想不需要手动实例化生成logger
fast_log 自带一个已经实例化好的 fs_logger 对象,你还嫌麻烦?
```python
from fast_log import fs_logger
fs_logger.debug('hello')
```
## 5 fast_log为什么快?
因为logging日志系统功能非常丰富强大,扩展性好,代码较为复杂,fast_log没有基于logging包来封装,是完全从0写的,代码简单自然就性能好了.
fast_log实现的文件日志多进程rotate切割安全,使用了特殊的方式,所以技能保证切割不报错又能保证性能.
nb_log是基于logging封装的,fast_log是手写的.
## 6 fast_log 日志截图
[![pPRvwGD.png](https://z1.ax1x.com/2023/09/14/pPRvwGD.png)](https://imgse.com/i/pPRvwGD)
Raw data
{
"_id": null,
"home_page": "https://github.com/ydf0509/fast_log",
"name": "fast-log-nb",
"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/f0/fd/a0f266f228d9b0660cf0d9b2d9d1cd860358f38784d09f6058655ab53fb6/fast_log_nb-0.3.tar.gz",
"platform": "all",
"description": "## 1 fast_log\r\n\r\n\u5b89\u88c5 pip install fast_log_nb\r\n\r\n#### \u8bb0\u4f4f\u5b89\u88c5\u662f pip install fast_log_nb ,\u4f7f\u7528\u662f import fast_log , \u56e0\u4e3a fast_log \u540d\u5b57\u5df2\u7ecf\u88ab\u4eba\u5360\u7528\u4e86\r\n\r\nfast_log \u662f\u6700\u5feb\u7684python\u65e5\u5fd7,\u6bd4loguru\u548clogging\u5feb30\u500d.\r\n\r\nfast_log\u7684\u63a7\u5236\u53f0\u65e5\u5fd7\u81ea\u52a8\u5f69\u8272.\r\n\r\nfast_log\u7684\u6587\u4ef6\u65e5\u5fd7\u591a\u8fdb\u7a0b\u5207\u5272\u5b89\u5168.\r\n\r\nfast_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\n### 1.2 \u4e3a\u4ec0\u4e48\u7528 fast_log\r\n\r\n```\r\n\u5185\u7f6e\u7684logging\u529f\u80fd\u5341\u5206\u4e30\u5bcc\u5f3a\u5927\u6269\u5c55\u6027\u597d,\u4f46\u5f88\u591a\u4eba\u4e0d\u61c2\u4ed6\u7684\u4e30\u5bcc\u529f\u80fd,\u6240\u4ee5\u5e73\u65f6\u4e5f\u6ca1\u7528\u5230\u90a3\u4e9b\u529f\u80fd. \r\n\u4f8b\u5982logging \u6811\u5f62\u7684\u547d\u540d\u7a7a\u95f4name,\u7528\u6237\u90fd\u4e0d\u77e5\u9053\r\n\r\n\u7528\u6237\u53ea\u662f\u7b80\u5355\u7684\u4f7f\u7528,\u90a3\u5c31\u53ef\u4ee5\u4e0d\u9700\u8981logging\u5305\u4e86\r\n```\r\n\r\n## 2 \u6027\u80fd\u6bd4\u8f83\r\n\r\n\u5728 win11 + r7 4800h\u4e0a\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\nfast_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 fast_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 fast_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 fast_log\u7684\u65e5\u5fd7\u7ea7\u522b\u548c\u5e38\u7528\u7684\u65e5\u5fd7\u662f\u4e00\u6837\u7684.\r\n\r\n```python\r\nimport logging\r\nimport time\r\n\r\nfrom fast_log.logger 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 fast_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\u7528\u6237\u662f\u6bcf\u4e2aname\u7684\u65e5\u5fd7\u884c\u4e3a\u662f\u72ec\u7acb\u7684,\u6240\u4ee5\u7528\u6237\u5728\u5927\u9879\u76ee\u4e2d\u6709\u5f88\u591a\u4e2a\u65e5\u5fd7,\u4e0d\u540c\u7684\u8868\u73b0\u884c\u4e3a,\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\nfast_log \u81ea\u5e26\u4e00\u4e2a\u5df2\u7ecf\u5b9e\u4f8b\u5316\u597d\u7684 fs_logger \u5bf9\u8c61,\u4f60\u8fd8\u5acc\u9ebb\u70e6?\r\n\r\n```python\r\nfrom fast_log import fs_logger\r\n\r\nfs_logger.debug('hello')\r\n```\r\n\r\n## 5 fast_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,fast_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\nfast_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,fast_log\u662f\u624b\u5199\u7684.\r\n\r\n## 6 fast_log \u65e5\u5fd7\u622a\u56fe\r\n\r\n[![pPRvwGD.png](https://z1.ax1x.com/2023/09/14/pPRvwGD.png)](https://imgse.com/i/pPRvwGD)\r\n\r\n",
"bugtrack_url": null,
"license": "BSD License",
"summary": "fast_log is most fast python log",
"version": "0.3",
"project_urls": {
"Homepage": "https://github.com/ydf0509/fast_log"
},
"split_keywords": [
"logging",
"log",
"logger",
"loguru",
"nb_log",
"rotate file"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0fda0f266f228d9b0660cf0d9b2d9d1cd860358f38784d09f6058655ab53fb6",
"md5": "e8a7bcadc03a20df1bd1b1ff2226b29d",
"sha256": "ae3b4271c767fd74c37909333df2ba0a65a2ec1d3fc160e2a14afaa93d5a86cf"
},
"downloads": -1,
"filename": "fast_log_nb-0.3.tar.gz",
"has_sig": false,
"md5_digest": "e8a7bcadc03a20df1bd1b1ff2226b29d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7648,
"upload_time": "2023-09-14T10:35:00",
"upload_time_iso_8601": "2023-09-14T10:35:00.014214Z",
"url": "https://files.pythonhosted.org/packages/f0/fd/a0f266f228d9b0660cf0d9b2d9d1cd860358f38784d09f6058655ab53fb6/fast_log_nb-0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-14 10:35:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ydf0509",
"github_project": "fast_log",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "fast-log-nb"
}