Skip to main content

二次封装 logging,更方便快捷的创建日志记录器。使用 gqylpy_log 模块可以快速创建 logging.Logger 实例并完成一系列的日志配置,使你的代码更简洁。

Project description

LOGO Release Python Versions License Downloads

gqylpy-log

二次封装 logging,更方便快捷的创建日志记录器。使用 gqylpy_log 模块可以快速创建 logging.Logger 实例并完成一系列的日志配置,使你的代码更简洁。

pip3 install gqylpy_log

使用内置的日志记录器

gqylpy_log 中内置了一个基于 logging.StreamHandler 的日志记录器,你可以直接调用它:

import gqylpy_log as glog

glog.debug(...)
glog.info(...)
glog.warning(...)
glog.error(...)
glog.critical(...)

它的默认配置如下:

level   = "NOTSET"
output  = "stream"
logfile = "/var/log/{default is your startup filename}.log"
datefmt = "%F %T"
logfmt  = "[%(asctime)s] [%(module)s.%(funcName)s.line%(lineno)d] [%(levelname)s] %(message)s"

当然可以修改它:

glog.level  = "INFO"

不过需要注意的是,你只有在第一次调用前修改内置的日志记录器配置才会生效,因为在你第一次调用时默认的日志记录器就已经被创建!

创建一个新的日志记录器
import gqylpy_log as glog

glog.__init__(
    "alpha",
    level  ="INFO",
    output ="stream,file",
    logfmt ="[%(asctime)s] [%(levelname)s] %(message)s",
    datefmt="%F %T",
    logfile="/var/log/alpha.log",
    gname  ="alpha"
)

glog.info(...)

或者你希望直接得到日志记录器实例,而不是始终通过 gqylpy_log 模块调用它:

log: logging.Logger = glog.__init__("beta", ...)
log.info(...)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gqylpy_log-1.2.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

gqylpy_log-1.2-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page