用于python日志记录的简单json格式化程序。

pylogops的Python项目详细描述


#pylogops
非常简单的用于python项目的json格式化程序。

[构建状态](https://travis ci.org/telefoniicaid/pylogops.svg)(https://travis ci.org/telefoniicaid/pylogops.svg)(https://github.com/telefoniicaid/pylogops/telefoniicaid/pylogops)



` `` bash
`` bash
`` bash
`` bash
`` bash

` ` `` bash
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `基本的用法
必须在标准python日志记录中使用的任何处理程序中指定格式化程序*jsonformatter*:

``py
导入日志记录
从pylogops导入时间
。logger导入jsonformatter

file\handler=logging.filehandler('/tmp/my\log.log',encoding='utf-8')
文件处理程序.setformatter(jsonformatter(converter=time.localtime))
日志记录.basicconfig()
日志记录程序=logging.getlogger(“我的日志记录程序”)
日志记录程序.addhandler(文件处理程序)
日志记录程序.setlevel(logging.info)
日志记录程序.info(“msg”)

`````
``````

**pylogps**默认生成JSON输出中的所有上部字段,但是您可以选择删除空字段:

``py
import logging
import time
from pylogops.logger import jsonformatter

file_handler=logging.filehandler('/tmp/my_log.log',encoding=-utf-8')
文件处理程序.setformatter(jsonformatter(remove庀blanks=true))
日志记录.basicconfig()
日志记录程序=logging.getlogger(“my庀logger”)
日志记录程序.addhandler(文件处理程序)
日志记录程序.setlevel(logging.info)
日志记录程序.info(“msg”)


```````
```json
{“time”:“2015-12-09t16:57:00.784z”,“lvl”:“info”,“comp”:“<;stdin>;”,“msg”:“msg”}
````


>您可以用python日志库提供的任何方式配置格式化程序,例如(dictconfig,fileconfig,…)。例如,您可以检查单元测试目录。

格式化程序中提供。您需要添加一个筛选器:

``py
import logging
import time
from pylogops.logger import trackingfilter,jsonformatter

file_handler=logging.filehandler('/tmp/my_log.log',encoding='utf-8')
file_handler.addfilter(trackingfilter())
file_handler.setformatter(jsonformatter(remove_blanks=true))
logging.basicconfig()
logger=logging.getlogger(“my_logger”)
logger.addhandler(file_handler)
logger.setlevel(logging.info)



=“trans”
本地上下文相关器本地上下文类型=“op”

logger.info(“msg”)
`````
这将生成json日志:
```json
{“time”:“2015-12-10t15:23:52.117z”,“lvl”:“info”,“corr”:“corr”,“trans”:“trans”,“op”:“op”,“comp”:“<;stdin gt;”,“msg”:“msg”}
```

local_context是在当前线程中为所有模块共享的thread.local();通常,您将在中间件或某种横向模块中包含这些值。



=file handler('/tmp/my-log.log.log日志/my-log.log,encoding='utf-8')
file-handler.setformatter(jsonformatter(keys-fmt=[('lvl','levelname'),('msg','消息'))))
logging.basicconfig()
logger=logging.getloglogger(“my-logger”)
logger.addhandler(file-addhandler(file-addhandler)logger.addhandler(file-addhandler)(file-addhandler(file-addhandler)
>logger.setlevellog.setlevellog(logger.log.info这个将生成一个json日志:

``json
{“lvl”:“info”,“msg”:“msg”}
```



您可以在http://www.apache.org/licenses/license-2.0


http://www.apache.org/licenses/license-2.0


获取许可证副本,除非适用法律要求或书面同意,否则根据许可证分发的软件是按“原样”分发的,无任何明示或暗示的保证或条件。请参阅许可证,以了解控制许可证下权限和限制的特定语言。

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

推荐PyPI第三方库


热门话题
java不适用于wildfly 8.2   java如何向ImageButton添加高程?   java如何使用带和空变量后缀的StrSubstitutor?   在AWS lambda上部署的springboot graphql应用程序中不允许使用java/graphql POST方法   java hiddenText=ca.a.getText();给出NullPointerException?   java如何将这两个正则表达式语句组合成一个字符串。repalcell()   java在Spring Boot中使用相同的存储库和实体创建多个数据源   用户界面如何在java GUI中检查复选框的状态?   更改Java列表中的引用   java一些HTTP请求不会出现在Fiddler中   java中带有<f:convertDateTime/>   jaxws+SSL中的java XML读取器错误XMLStreamException   html解析如何在java中使用Jsoup浏览网站   java Jackson如何在客户端代码中反序列化自定义的多态类型?   java字段、方法、基于类的注入有什么区别?我们如何使用这种注射剂?serviceResource注释需要哪些更改   java JPA:使用字符串字段,但修改它们并另存为字节数组