复杂的日志记录,简单的api

loggylog的Python项目详细描述


复杂的日志记录,简单的api

安装

来自PYPI:

$ pip install loggylog

从项目根目录:

$ python setup.py install

用法

您只需实例化一个记录器,并给它一个日志级别。 日志级别可以是字符串或列表。如果是一根绳子,它会 日志级别或更高级别的日志,例如'warning'指定警告、严重或错误。

如果使用列表,它将只写入那些日志级别。['warning']只会写 该文件的警告级别日志消息。

使用逗号分隔的值(如'info,error')指定字符串相当于 使用['info', 'error'],以便通过命令行作为字符串传递。

如果sudo=True,它将查看是否有权限写入路径,如果没有,或者 文件不存在,它没有在那里创建文件的权限,它将 请求sudo的许可并修改文件。如果你已经得到许可,这是没有效果的, 但是对于首次运行写入/var/log/example.log但不写入/var/log/example.log的应用程序很有用 得到许可。

它还透明地使用string方法format,因此可以按预期工作:

>>> log.critical('Approaching {percent:.2%} the speed of light', percent=0.55554)
'Approaching 55.55% the speed of light'

有关更多示例,请参见格式documentation

API使用示例:

from loggylog import Logger

log = Logger()

# default is to write all log messages
log.add_log('./myproject.log')

# write everything but debug level to ./myproject.log
log.add_log('./myproject.log', level='info')

# write error logging to myproject_error.log
log.add_log('./myproject_error.log', level='error')

# display to standard out the following log levels
log.add_log('<stdout>', level=['warning', 'critical', 'error'])

# 'warning' is the same as ['warning', 'critical', 'error'] or just 'warning'
# sudo=True will make sure it has permission to write to a file with that
# path, or get sudo and chown and chmod it appropriately.
log.add_log('/var/log/myproject.log', level='warning', sudo=True)

# ['error'] will just write only error logging
log.add_log('just_errors.log', level=['error'])

# if for some reason CSV is more convenient than a list...
log.add_log('info_and_warning.log', level='info,warning')

# Basic logging
log.debug('debuggybug')
log.info('i got something to tell you')
log.warning('winter is coming')
log.critical('critical temperature in reactor')
log.error('sumthin brken')

# Also, it transparently uses string formatting
log.info("We're going to build a {}", 'wall')
log.info("It's going to be {size}", size='yuge')
# Ordering by integers in braces
log.critical("{1} for {0}", 'me', 'vote')
# See https://docs.python.org/3.1/library/string.html#format-examples
# for more examples.

发行说明

0.0.1:Project created

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

推荐PyPI第三方库


热门话题
反射Java反射:高负载下的NoSuchMethodException   java RxJava:one request>list of Integer>sequence of requests for each int>result to list   java为什么循环之前索引会增加   JavaSpring远程处理和RESTfulURL   java Hibernate搜索仅对我的实体的一部分进行索引   使用DPAD快速滚动时,java RecyclerView onCreateViewHolder调用过多   java将JSON解析到一个表中   java导航抽屉标题textview nullpointerexception   基于接口的Java链接队列   java Guice运行时依赖项参数重新注入   java展平/压缩ZSH中的深度嵌套目录   JavaSpring:Http406此请求标识的资源只能   java如何制作Android启动器图标   Java代码在windows上显示不正确(包含希腊语句子)   使用yourkit进行内存分析所用的java时间   java为什么可以序列化属性而不能序列化对象本身?