diff --git a/docs/api/log.md b/docs/api/log.md index ecc3bdc3..fdc24b50 100644 --- a/docs/api/log.md +++ b/docs/api/log.md @@ -7,9 +7,9 @@ sidebarDepth: 0 ## 日志 -NoneBot 使用标准库 [logging](https://docs.python.org/3/library/logging.html) 来记录日志信息。 +NoneBot 使用 [loguru](https://github.com/Delgan/loguru) 来记录日志信息。 -自定义 logger 请参考 [logging](https://docs.python.org/3/library/logging.html) 文档。 +自定义 logger 请参考 [loguru](https://github.com/Delgan/loguru) 文档。 ## `logger` diff --git a/nonebot/log.py b/nonebot/log.py index ae03d2f3..8218ca57 100644 --- a/nonebot/log.py +++ b/nonebot/log.py @@ -4,18 +4,21 @@ 日志 ==== -NoneBot 使用标准库 `logging`_ 来记录日志信息。 +NoneBot 使用 `loguru`_ 来记录日志信息。 -自定义 logger 请参考 `logging`_ 文档。 +自定义 logger 请参考 `loguru`_ 文档。 -.. _logging: - https://docs.python.org/3/library/logging.html +.. _loguru: + https://github.com/Delgan/loguru """ import sys -import logging +# import logging -logger = logging.getLogger("nonebot") +from loguru import logger as logger_ + +# logger = logging.getLogger("nonebot") +logger = logger_ """ :说明: @@ -38,7 +41,13 @@ logger = logging.getLogger("nonebot") logger = logging.getLogger("nonebot") """ -default_handler = logging.StreamHandler(sys.stdout) -default_handler.setFormatter( - logging.Formatter("[%(asctime)s %(name)s] %(levelname)s: %(message)s")) -logger.addHandler(default_handler) +# default_handler = logging.StreamHandler(sys.stdout) +# default_handler.setFormatter( +# logging.Formatter("[%(asctime)s %(name)s] %(levelname)s: %(message)s")) +# logger.addHandler(default_handler) + +logger.remove() +default_format = ("{level: <8}|" + "{time:MM-DD HH:mm:ss}|" + "{message}") +logger.add(sys.stdout, colorize=True, format=default_format) diff --git a/poetry.lock b/poetry.lock index b7a98f4e..5588003d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -99,7 +99,7 @@ type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" [[package]] -category = "dev" +category = "main" description = "Cross-platform colored terminal text." marker = "sys_platform == \"win32\"" name = "colorama" @@ -332,6 +332,26 @@ reference = "aliyun" type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" +[[package]] +category = "main" +description = "Python logging made (stupidly) simple" +name = "loguru" +optional = false +python-versions = ">=3.5" +version = "0.5.1" + +[package.dependencies] +colorama = ">=0.3.4" +win32-setctime = ">=1.0.0" + +[package.extras] +dev = ["codecov (>=2.0.15)", "colorama (>=0.3.4)", "flake8 (>=3.7.7)", "isort (>=4.3.20)", "tox (>=3.9.0)", "tox-travis (>=0.12)", "pytest (>=4.6.2)", "pytest-cov (>=2.7.1)", "Sphinx (>=2.2.1)", "sphinx-autobuild (>=0.7.1)", "sphinx-rtd-theme (>=0.4.3)", "black (>=19.3b0)"] + +[package.source] +reference = "aliyun" +type = "legacy" +url = "https://mirrors.aliyun.com/pypi/simple" + [[package]] category = "dev" description = "Safely add untrusted strings to HTML/XML markup." @@ -603,6 +623,7 @@ yapf = "*" reference = "1438d33cbeaab0230c9f7e33bd059eb9f57c86d6" type = "git" url = "https://github.com/nonebot/sphinx-markdown-builder.git" + [[package]] category = "dev" description = "sphinxcontrib-applehelp is a sphinx extension which outputs Apple help books" @@ -833,6 +854,23 @@ reference = "aliyun" type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" +[[package]] +category = "main" +description = "A small Python utility to set file creation time on Windows" +marker = "sys_platform == \"win32\"" +name = "win32-setctime" +optional = false +python-versions = ">=3.5" +version = "1.0.1" + +[package.extras] +dev = ["pytest (>=4.6.2)", "black (>=19.3b0)"] + +[package.source] +reference = "aliyun" +type = "legacy" +url = "https://mirrors.aliyun.com/pypi/simple" + [[package]] category = "dev" description = "A formatter for Python code." @@ -848,10 +886,9 @@ url = "https://mirrors.aliyun.com/pypi/simple" [extras] scheduler = ["apscheduler"] -test = [] [metadata] -content-hash = "4d16d7ad0930bc9851802bc149f843c4e990a987e89414d765579ea8dccc8d6e" +content-hash = "2e8f1fc9fcb89a528ecbebbf0f2315abf39e3de8eb40c133b91085a784e49173" python-versions = "^3.7" [metadata.files] @@ -949,6 +986,10 @@ jinja2 = [ {file = "Jinja2-2.11.2-py2.py3-none-any.whl", hash = "sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035"}, {file = "Jinja2-2.11.2.tar.gz", hash = "sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0"}, ] +loguru = [ + {file = "loguru-0.5.1-py3-none-any.whl", hash = "sha256:e5d362a43cd2fc2da63551d79a6830619c4d5b3a8b976515748026f92f351b61"}, + {file = "loguru-0.5.1.tar.gz", hash = "sha256:70201d5fce26da89b7a5f168caa2bb674e06b969829f56737db1d6472e53e7c3"}, +] markupsafe = [ {file = "MarkupSafe-1.1.1-cp27-cp27m-macosx_10_6_intel.whl", hash = "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161"}, {file = "MarkupSafe-1.1.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"}, @@ -1136,6 +1177,10 @@ websockets = [ {file = "websockets-8.1-cp38-cp38-win_amd64.whl", hash = "sha256:f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b"}, {file = "websockets-8.1.tar.gz", hash = "sha256:5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f"}, ] +win32-setctime = [ + {file = "win32_setctime-1.0.1-py3-none-any.whl", hash = "sha256:568fd636c68350bcc54755213fe01966fe0a6c90b386c0776425944a0382abef"}, + {file = "win32_setctime-1.0.1.tar.gz", hash = "sha256:b47e5023ec7f0b4962950902b15bc56464a380d869f59d27dbf9ab423b23e8f9"}, +] yapf = [ {file = "yapf-0.30.0-py2.py3-none-any.whl", hash = "sha256:3abf61ba67cf603069710d30acbc88cfe565d907e16ad81429ae90ce9651e0c9"}, {file = "yapf-0.30.0.tar.gz", hash = "sha256:3000abee4c28daebad55da6c85f3cd07b8062ce48e2e9943c8da1b9667d48427"}, diff --git a/pyproject.toml b/pyproject.toml index 5f222f53..9c3f8e41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,15 +27,16 @@ fastapi = "^0.58.1" uvicorn = "^0.11.5" pydantic = { extras = ["dotenv"], version = "^1.6.1" } apscheduler = { version = "^3.6.3", optional = true } -nonebot-test = { version = "^0.1.0", optional = true } +# nonebot-test = { version = "^0.1.0", optional = true } +loguru = "^0.5.1" [tool.poetry.dev-dependencies] yapf = "^0.30.0" sphinx = "^3.1.1" sphinx-markdown-builder = { git = "https://github.com/nonebot/sphinx-markdown-builder.git" } [tool.poetry.extras] -test = ["nonebot-test"] +# test = ["nonebot-test"] scheduler = ["apscheduler"] [[tool.poetry.source]]