1 Star 1 Fork 6

Rockman0 / thenextquant_github

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logger.md 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
Demon-Hunter 提交于 2019-06-18 15:29 . update docs

日志打印

日志可以分多个级别,打印到控制台或者文件,文件可以按天分割存储。

1. 日志配置
{
    "LOG": {
        "console": true,
        "level": "DEBUG",
        "path": "/var/log/servers/Quant",
        "name": "quant.log",
        "clear": true,
        "backup_count": 5
    }
}

参数说明:

  • console boolean 是否打印到控制台,true 打印到控制台 / false 打印到文件,可选,默认为 true
  • level string 日志打印级别 DEBUG/ INFO,可选,默认为 DEBUG
  • path string 日志存储路径,可选,默认为 /var/log/servers/Quant
  • name string 日志文件名,可选,默认为 quant.log
  • clear boolean 初始化的时候,是否清理之前的日志文件,true 清理 / false 不清理,可选,默认为 false
  • backup_count int 保存按天分割的日志文件个数,默认0为永久保存所有日志文件,可选,默认为 0

配置文件可参考 服务配置模块;

2. 导入日志模块
from quant.utils import logger

logger.debug("a:", 1, "b:", 2)
logger.info("start strategy success!", caller=self)  # 假设在某个类函数下调用,可以打印类名和函数名
logger.warn("something may notice to me ...")
logger.error("ERROR: server down!")
logger.exception("something wrong!")
3. INFO日志
def info(*args, **kwargs):
4. WARNING日志
def warn(*args, **kwargs):
4. DEBUG日志
def debug(*args, **kwargs):
5. ERROR日志
def error(*args, **kwargs):
6. EXCEPTION日志
def exception(*args, **kwargs):

注意:

  • 所有函数的 argskwargs 可以传入任意值,将会按照python的输出格式打印;
  • kwargs 中指定 caller=selfcaller=cls,可以在日志中打印出类名及函数名信息;
1
https://gitee.com/rockman0/thenextquant_github.git
git@gitee.com:rockman0/thenextquant_github.git
rockman0
thenextquant_github
thenextquant_github
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891