python“logging”功能的扩展。

logging-fortified的Python项目详细描述


强化伐木

这个python项目是本地python组件logging的扩展。 为标准和json日志输出提供更健壮的消息格式,并允许额外的 作为字典填充的内容。

重要提示

这个python项目是logging-mv-integrations的重构 出于一般使用目的。

进行中的工作

此python项目仍需要执行以下操作:

  • 单元测试:这个项目将切换到使用python本机单元测试框架unittest
  • 需要更简明的文件。
  • 特拉维斯ci
  • 徽章

徽章

docsDocumentation StatusLicense Status
packagePyPI Package latest releaseSupported versions

安装

pip install logging_fortified

架构

logging-fortifiedlogging facility for Python的扩展 用于提供自定义记录器级别、格式和输出。

UML logging-fortified

函数:get_logger()

defget_logger(logger_name,logger_version=None,logger_level=logging.INFO,logger_format=LoggingFormat.JSON,logger_output=LoggingOutput.STDOUT_COLOR,logger_handler=None):

get_logger():参数

ParameterPurpose
logger_nameReturn a logger with the specified name or, if name is None, return a logger which is the root logger of the hierarchy.
logger_version
logger_formatLoggingFormat
logger_outputLoggingOutput
logger_handlerlogging.StreamHandler() or logging.FileHandler()

测井水平

相同的python日志记录级别,包括一个额外的级别说明。

LevelPurpose
DEBUGDetailed information, typically of interest only when diagnosing problems.
NOTEDetailed information, request processing, for example, request using cURL.
INFOConfirmation that things are working as expected. [DEFAULT]
WARNINGAn indication that something unexpected happened, or indicative of some problem in the near future. The software is still working as expected.
ERRORDue to a more serious problem, the software has not been able to perform some function.
CRITICALA serious error, indicating that the program itself may be unable to continue running.

日志格式

FormatPurpose
STANDARDStandard logging format.
JSONJSON logging format. [DEFAULT]
classLoggingFormat(object):"""TUNE Logging Format ENUM
    """STANDARD="standard"JSON="json"

记录输出

OutputPurpose
STDOUTStandard Output to terminal
STDOUT_COLORStandard Output using colored terminal
FILEStandard Output to file created within ./tmp/log_<epoch time seconds>.json.
classLoggingOutput(object):"""Logging Format ENUM
    """STDOUT="stdout"STDOUT_COLOR="color"FILE="file"

记录json格式

importloggingfromlogging_fortifiedimport(LoggingFormat,get_logger,__version__)log=get_logger(logger_name=__name__,logger_version=__version__,logger_format=LoggingFormat.JSON,logger_level=logging.NOTE)log.info("logging: info",extra={'test':__name__})log.note("logging: note",extra={'test':__name__})log.debug("logging: debug",extra={'test':__name__})log.warning("logging: warning",extra={'test':__name__})log.error("logging: error",extra={'test':__name__})log.critical("logging: critical",extra={'test':__name__})log.exception("logging: exception",extra={'test':__name__})

记录json示例输出

$ python3 examples/example_logging_json.py

{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "INFO", "name": "__main__",
"version": "0.1.6", "message": "logging: info", "test": "__main__"}{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "NOTE", "name": "__main__",
"version": "0.1.6", "message": "logging: note", "test": "__main__"}{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "WARNING", "name": "__main__",
"version": "0.1.6", "message": "logging: warning", "test": "__main__"}{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "ERROR", "name": "__main__",
"version": "0.1.6", "message": "logging: error", "test": "__main__"}{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "CRITICAL", "name": "__main__",
"version": "0.1.6", "message": "logging: critical", "test": "__main__"}{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "ERROR", "name": "__main__",
"version": "0.1.6", "message": "logging: exception", "exc_info": "NoneType: None",
"test": "__main__"}

要求

logging-fortified模块基于python 3构建,并且依赖于 Python Package Index PyPI中提供了几个python模块。

make install-requirements

python3 -m pip uninstall --yes --no-input -r requirements.txt
python3 -m pip install --upgrade -r requirements.txt

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

推荐PyPI第三方库


热门话题
java用变化的替换字符串替换子字符串   从数据库中断中恢复的oracle Java DAL?   Android/Java页边距位于左/右/底部   java如何用相同的源代码构建不同的APK?(我发现了一个错误)   java正则表达式,仅当字符串以一行中的3个数字开头时才匹配第一个数字   使用以xml为输入的给定端点调用java中的rest-ful web服务?   java长字符串转换为UTF8引发异常   java如何使用截取方法获取ArrayList   java将计算列添加到可观察列表中   正则表达式如何在java正则表达式中使用组?   java正则表达式只接受字母表和空格,不允许在字符串的开头和结尾使用空格   java简单onclick按钮在安卓中不起作用   java如何在Spring中只实现Crudepository的特定方法?   java无法使用json对象NPE读取jsonarray   java我可以添加maven依赖项,这些依赖项被打包为除此之外的任何东西。罐子