简单日志工具

SimpleLogger的Python项目详细描述


simpleLogger是一个简单的python日志工具。我发现默认的python日志模块功能强大,但非常笨拙,很难快速设置。SimpleLogger支持基本功能,如输出重定向、自定义日志格式和日志级别。

用法:

日志级别和阈值:

通过Logger.set_threshold设置当前阈值,该阈值确定可以看到的日志项级别,并将常量作为参数传递。级别常量包括debug、info、warning、error和critical。更改阈值只会影响将来的条目。

日志格式:

日志记录格式是通过Logger.set_format设置的,传递一个有效字符字符串和替换指令作为参数。

有效的补贴指令包括:

DirectiveSubstitution
{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/>;。

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

推荐PyPI第三方库


热门话题
Java中的多个控制台或显示屏?   java Guava:是否可能不使用多重映射映射所有条目。索引()?   java转换键值对作为JSON响应的对象?   java读取一个文本文件,然后计算字母频率,并从高到低列出它们   java Apache CXF为客户提供SEI   java如何在SQL查询中“转义”整个字符串   将JavaServlet定义为主网页servlet注释不起作用   运行jar文件时发生java FileNotFoundException   java有两种加载FXML的方法;为什么一个比另一个更受欢迎?   java无法切换到timeofindia站点页面中的帧   java Firebase Firestore在连接丢失后需要很长时间才能重新连接   java使用来自SQLite的通用数据填充RecyclerView/ListView   当我使用offer和poll独占访问它时,java是LinkedList线程安全的吗?   如何使用包含Java命名空间的XPath检索XML数据?   Spring Boot的java Elasticsearch Searchguard配置   java数组中的数组值赋值?   java保存成功,但更新失败使用Jointable的多对多Spring JPA和额外列   kotlin什么是java。构造器。单()?   简单解析例程的java问题