python的日志替代品

Logbook的Python项目详细描述


一个很棒的日志实现,使用起来很有趣。

快速启动

from logbook import Logger
log = Logger('A Fancy Name')

log.warn('Logbook is too awesome for most applications')
log.error("Can't touch this")

也适用于Web应用程序

from logbook import MailHandler, Processor

mailhandler = MailHandler(from_addr='servererror@example.com',
                          recipients=['admin@example.com'],
                          level='ERROR', format_string=u'''\
Subject: Application Error for {record.extra[path]} [{record.extra[method]}]

Message type:       {record.level_name}
Location:           {record.filename}:{record.lineno}
Module:             {record.module}
Function:           {record.func_name}
Time:               {record.time:%Y-%m-%d %H:%M:%S}
Remote IP:          {record.extra[ip]}
Request:            {record.extra[path]} [{record.extra[method]}]

Message:

{record.message}
''')

def handle_request(request):
    def inject_extra(record, handler):
        record.extra['ip'] = request.remote_addr
        record.extra['method'] = request.method
        record.extra['path'] = request.path

    with Processor(inject_extra):
        with mailhandler:
            # execute code that might fail in the context of the
            # request.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
实例化对象时发生java编译错误   java通过constraintSet以编程方式设置约束会导致视图消失   无法使用maven部署将java应用程序重新部署到tomcat7   真正调用bean之后的JavaSpring延迟加载   java如何在Android Studio中初始化处理程序?   泛型Java,不同对象的重复逻辑块,清理代码   java Apache Camel文件队列需要NOOP使用者的目录写入权限?   java<mvc:resources>我可以指向location=“http:path/to/s3/bucket”吗?   java如何为eclipse运行配置提供kotlin类?   不同项目之间的java Guice依赖项注入   java Android聊天客户端:socket连接   java JPA。JoinTable和两个JointColumns   java编写CANopen测试实用程序