fast-logger-test


Namefast-logger-test JSON
Version 0.1 PyPI version JSON
download
home_page
Summaryfast_log is most fast python log
upload_time2023-09-14 10:15:38
maintainerydf
docs_urlNone
authorbfzs
requires_python
licenseBSD License
keywords logging log logger loguru nb_log rotate file
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## 1 fast_log

安装 pip install 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 日志截图

![img_1.png](img_1.png)


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fast-logger-test",
    "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/37/2f/09e3afa2f2fd7ded7c13e47e0526bc346be563517f92ad521ce9f79dcf9c/fast_logger_test-0.1.tar.gz",
    "platform": "all",
    "description": "## 1 fast_log\r\n\r\n\u5b89\u88c5 pip install fast_log\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![img_1.png](img_1.png)\r\n\r\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "fast_log is most fast python log",
    "version": "0.1",
    "project_urls": null,
    "split_keywords": [
        "logging",
        "log",
        "logger",
        "loguru",
        "nb_log",
        "rotate file"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "372f09e3afa2f2fd7ded7c13e47e0526bc346be563517f92ad521ce9f79dcf9c",
                "md5": "4f5ef552fa51bedf8a0bd8ef5744aebd",
                "sha256": "55acb77a6bcee1cee69f51c1f184e71320d808e06eda484342d620e9120a68b8"
            },
            "downloads": -1,
            "filename": "fast_logger_test-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4f5ef552fa51bedf8a0bd8ef5744aebd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7534,
            "upload_time": "2023-09-14T10:15:38",
            "upload_time_iso_8601": "2023-09-14T10:15:38.544164Z",
            "url": "https://files.pythonhosted.org/packages/37/2f/09e3afa2f2fd7ded7c13e47e0526bc346be563517f92ad521ce9f79dcf9c/fast_logger_test-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 10:15:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fast-logger-test"
}
        
Elapsed time: 0.27175s