轻松配置日志记录
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