轻松配置日志记录

easylogconfig的Python项目详细描述


易配置

这个python库为standart日志模块提供了简单的包装。

如果你想要的不仅仅是“logging.basicconfig”,但是不想读太多 documentation写了很多代码。

用法

您可以在./examples目录中找到示例

importloggingimporteasylogconfiglog=logging.getLogger(__name__)# print messages to the stdout, add debug leveleasylogconfig.auto(debug=True)# or print messages to the syslogeasylogconfig.auto(syslog_tag="example_tag")# or print messages to the file without datetime but with thread nameseasylogconfig.auto(file_name="/var/log/example.log",file_backup_count=30,datetime=False,thread=True)log.info("info message")log.debug("debug message")# output format:# 2019-03-22/10:17:28 INFO    info message

配置

库提供一个简单的函数auto和参数:

  • 格式化程序参数:
    • debug=false:是否向输出添加调试消息?
    • thread=false:向消息添加线程名?
    • datetime=true:向消息添加datetime?
    • level=false:向消息添加级别名称?
  • SysLogHandler参数:
    • syslog_tag=none:如果设置为str,则使用此标记将消息记录到syslog
    • syslog\u address=“/dev/log”:系统日志服务器地址
  • TimedRotatingFileHandler参数:
    • file_name=none:如果设置为str,则将消息记录到此磁贴
    • file_when=“午夜”:文件旋转时间
    • file_backup_count=7:保留最后的文件

如果要将消息记录到stdout,请不要传递syslog_标记file_name参数。如果 要将消息记录到syslog服务器,请传递syslog_tag参数。如果你想登录 消息到文件,传递file_name参数。

安装

pip install -U easylogconfig
# or
pip install -U git+https://github.com/tierpod/easylogconfig#egg=easylogconfig

开发

make venv
sourve ./venv/bin/activate
make init-dev init

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

推荐PyPI第三方库


热门话题
java如何将向量的内容从一个包发送到另一个包?   java无法扩展类并对ArrayList进行排序   java无法对字符串的ArrayList进行排序   JavaP:ajax更改事件请求返回500错误   java如何为TableHeader使用渲染器   带有记号的java JSlider问题   Java如何在不同的类中调用add()方法   java如何使用JDBC和HSQLDB检索以前自动生成的PK ID值   java如何使dropwizard应用程序在启动完成之前忽略所有调用   使用MethodValidationPostProcessor进行java Spring验证   java Mediaplayer错误(19 0)不适用于release()   java UnsatifiedPendencyException Swigger2+Sringboot+@RestClientTest   java如何从onActivityResult更新回收器视图元素   java基于图像添加地板或如何优化已有方法   jComboBox的java奇怪行为   java从数据库表php中提取信息   Android-sqlite更新方法;JAVAlang.IllegalStateException:无法执行活动的方法   java如何将多个XSD文件合并到一个XSD文件?   java在不使用大多数API的情况下消除空格