改进了瓶子的记录。
bottle-log的Python项目详细描述
改进了瓶子的记录。
使用
为了捕获其他插件的异常,loggingplugin应该是 安装到应用程序的第一个插件。
importbottlefrombottle_logimportLoggingPluginapp=bottle.Bottle()app.install(LoggingPlugin(app.config))@app.get('/test')deftest(logger):logger.warning('This is only a test')return{}
配置
该插件使用以下配置键:
logging.level
日志级别可能值:调试,信息,警告,错误,关键。 默认为警告
日志记录。格式
日志记录格式。有关格式,请参阅python日志记录文档。 默认为“[%(asctime)s]%(levelname)s:%(name)s:%(消息)s”
logging.utc
如果true,则默认时间戳以UTC为单位。
日志记录
默认情况下,由logger关键字使用的标准记录器将打印到stderr
异常日志记录
这个插件还提供了一个异常记录器(“bottle.exception”)默认情况下 这个记录器什么也不做,因为bottle将所有异常都打印到stderr,但是它可以 如果要将异常记录到其他地方,则此选项非常有用。 例如,记录到日志条目:
importbottlefromlogentriesimportLogentriesHandlerfrombottle_logimportLoggingPluginapp=bottle.Bottle()app.install(LoggingPlugin(app.config))le_handler=LogentriesHandler('logentries-api-token')logging.getLogger('bottle.exception').addHandler(le_handler)