2020-06-30 10:13:58 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
2020-08-20 15:07:05 +08:00
|
|
|
|
"""
|
|
|
|
|
日志
|
|
|
|
|
====
|
|
|
|
|
|
2020-08-26 22:54:58 +08:00
|
|
|
|
NoneBot 使用 `loguru`_ 来记录日志信息。
|
2020-08-20 15:07:05 +08:00
|
|
|
|
|
2020-08-26 22:54:58 +08:00
|
|
|
|
自定义 logger 请参考 `loguru`_ 文档。
|
2020-08-20 15:07:05 +08:00
|
|
|
|
|
2020-08-26 22:54:58 +08:00
|
|
|
|
.. _loguru:
|
|
|
|
|
https://github.com/Delgan/loguru
|
2020-08-20 15:07:05 +08:00
|
|
|
|
"""
|
2020-06-30 10:13:58 +08:00
|
|
|
|
|
|
|
|
|
import sys
|
2020-08-26 22:54:58 +08:00
|
|
|
|
# import logging
|
2020-06-30 10:13:58 +08:00
|
|
|
|
|
2020-08-26 22:54:58 +08:00
|
|
|
|
from loguru import logger as logger_
|
|
|
|
|
|
|
|
|
|
# logger = logging.getLogger("nonebot")
|
|
|
|
|
logger = logger_
|
2020-08-20 15:07:05 +08:00
|
|
|
|
"""
|
|
|
|
|
:说明:
|
|
|
|
|
|
|
|
|
|
NoneBot 日志记录器对象。
|
|
|
|
|
|
|
|
|
|
:默认信息:
|
|
|
|
|
|
|
|
|
|
* 格式: ``[%(asctime)s %(name)s] %(levelname)s: %(message)s``
|
|
|
|
|
* 等级: ``DEBUG`` / ``INFO`` ,根据 config 配置改变
|
|
|
|
|
* 输出: 输出至 stdout
|
|
|
|
|
|
|
|
|
|
:用法:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from nonebot.log import logger
|
|
|
|
|
|
|
|
|
|
# 也可以这样
|
|
|
|
|
import logging
|
|
|
|
|
logger = logging.getLogger("nonebot")
|
|
|
|
|
"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
2020-08-26 22:54:58 +08:00
|
|
|
|
# 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 = ("<lvl>{level: <8}</lvl>|"
|
|
|
|
|
"<green>{time:MM-DD HH:mm:ss}</green>|"
|
|
|
|
|
"<lvl>{message}</lvl>")
|
|
|
|
|
logger.add(sys.stdout, colorize=True, format=default_format)
|