简单日志工具
SimpleLogger的Python项目详细描述
simpleLogger是一个简单的python日志工具。我发现默认的python日志模块功能强大,但非常笨拙,很难快速设置。SimpleLogger支持基本功能,如输出重定向、自定义日志格式和日志级别。
用法:
日志级别和阈值:
通过Logger.set_threshold设置当前阈值,该阈值确定可以看到的日志项级别,并将常量作为参数传递。级别常量包括debug、info、warning、error和critical。更改阈值只会影响将来的条目。
日志格式:
日志记录格式是通过Logger.set_format设置的,传递一个有效字符字符串和替换指令作为参数。
有效的补贴指令包括:
Directive | Substitution |
---|---|
{time} | The current time |
{datetime} | The current date and time |
{date} | The current date |
{level} | The level of the entry |
{text} | The text to be logged |
安装:
推荐:
pip install simplelogger
艰难的道路:
python setup.py install
示例:
基本用法::
import simplelogger # make a new logger that outputs to output_file.log, has a threshold of DEBUG, and the entry format is just the text to be logged logger = simplelogger.Logger(stream=output_file.log, threshold=simplelogger.DEBUG, format="{text}") logger.info("Log at the info level") logger.warning("Log at the warning level") if (foo > bar): # change the logging threshold to INFO logger.set_threshold(simplelogger.INFO) else: # change the format to output the logged text, the date and time, and the time separated by characters logger.set_format("{text}: {datetime} - {time}")
许可证
版权所有(c)2013 Tayler Mulligan
此程序是免费软件:您可以重新分发和/或修改 根据由 自由软件基金会,或者许可证的第3版,或者 (由您选择)任何更高版本。
这个程序的发布是希望它能有用, 但没有任何保证;甚至没有 适销性或适合某一特定目的的适销性。见 GNU通用公共许可证了解更多详细信息。
你应该收到GNU通用公共许可证的副本 还有这个节目。如果没有,请参见<;http://www.gnu.org/licenses/>;。