用于日志记录的包装器模块,具有开箱即用的日志轮换和严重错误邮件功能

autopylogger的Python项目详细描述


自动定位器

Python线程安全日志包装器模块,提供开箱即用的日志轮换和关键日志邮寄功能,可在任何Python脚本中实现无缝集成。在

要求:日志记录

基本用法:

  • 通过调用“init\u logging”函数(关闭邮件功能)初始化logger对象

      from autopylogger import init_logging
      my_logger_obj = init_logging(log_name='my_logs', log_directory='logs_dir')
    
  • 通过调用'init\u logging'函数(邮件功能打开)初始化logger对象

    ^{pr2}$

    注意:从v2020.2.11以上的版本开始,默认情况下会启用严重错误邮件功能

  • 使用该对象编写调试|信息|警告|错误日志

      my_logger_obj.debug('This is DEBUG log')
      my_logger_obj.info('This is INFO log')
      my_logger_obj.warning('This is WARNING log')
      my_logger_obj.error('This is ERROR log')
      my_logger_obj.critical('This is CRITICAL log. Mail will be sent with this message')
    

重要标志:

  • 设置日志级别:将适当的值传递给“logаlevel”标志。

      log_level = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR'
    
  • 打开/关闭控制台日志:将适当的值传递给“console\ulog”标志。

      console_log = True | False
    

    注意:建议在程序作为服务运行时关闭生产环境中的控制台日志记录,以防止使用信息消息刷新系统控制台日志。在linux系统中。

  • {str{/str}适当的{/str}设置{/str}适当的{/str}标准。

      rotation_criteria = 'size' | 'time' | 'timeandsize'
    

    默认情况下,旋转条件“size”用于最大文件大小200 MB。在

    • 选择基于“size”的旋转条件时,传递参数值'max\u bytes'以指定日志文件的最大大小(以字节为单位)。在

      'rotation_criteria' = 'size'
      'max_bytes' = 5*1024*1024
      
    • 当选择基于“time”的旋转条件时,请传递参数值“rotate\”When“&;”rotate\\ interval“。在

      'rotation_criteria' = 'time'
      'rotate_when' = 'd' | 'h' | 'm' | 's'
      'rotate_interval' = 1 (for rotating log every 1 day|hour|minute|second)
      
    • 当选择基于“timeandsize”的旋转条件时,传递参数值“rotate_When”“rotate_interval”&;'max\u bytes'。在

      'rotation_criteria' = 'timeandsize'
      'max_bytes' = 5*1024*1024
      'rotate_when' = 'd' | 'h' | 'm' | 's'
      'rotate_interval' = 1 (for rotating log every 1 day|hour|minute|second)
      

    注意:在“timeandsize”旋转条件中,当满足时间或大小约束时,文件将被旋转。“

  • 打开/关闭关键邮件:将布尔值(TRUE | FALSE)传递给“启用邮件”标志。默认情况下,对严重错误启用邮件功能。

    • “enable\u mail”设置为True时,需要以下标志。在

      'mailfrom_addr' = '<Sender email address>'
      'mailto_addr' = '<Receiver email address>'
      'mail_subject' = '<Mail subject>'
      'mail_credentials' = ('<username>', '<password>') or None if no authentication is required.
      
  • 正在设置日志格式:将所需的日志格式字符串传递给“log_format”标志

      log_format='[%(asctime)s] -- %(levelname)s - %(filename)s -- %(funcName)s - Line no - %(lineno)d -- %(message)s'
    
日志格式化程序参数:
FormatDescription
%(asctime)sHuman-readable time when the LogRecord was created. By default this is of the form ‘2003-07-08 16:49:45,896’ (the numbers after the comma are millisecond portion of the time).
%(created)fTime when the LogRecord was created (as returned by time.time()).
%(filename)sFilename portion of pathname.
%(funcName)sName of function containing the logging call.
%(levelname)sText logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
%(lineno)dSource line number where the logging call was issued (if available).
%(message)sThe logged message, computed as msg % args. This is set when Formatter.format() is invoked.
%(msecs)dMillisecond portion of the time when the LogRecord was created.
%(name)sName of the logger used to log the call.
%(pathname)sFull pathname of the source file where the logging call was issued (if available).
%(process)dProcess ID (if available).
%(processName)sProcess name (if available).
%(thread)dThread ID (if available).
%(threadName)sThread name (if available).

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

推荐PyPI第三方库


热门话题
使用JNI在Java中调用C#代码的基本(实用)教程   java获取列表的最小和最大字符串   Java Spring异常中的延迟加载   安卓的java LWJGL端口   安卓上的java按下音量按钮?   C#相当于Java的线程。设置守护进程?   java Android Studio未能解析:com。github。Udhayarajan:liquidswipe安卓:1.0.1   Spring引导集成中MQTTPAHomeMessageHandler和MQTTPAHomeMessageDrivenChannelAdapter之间共享相同MQTT客户端实例的java   环境中的Android Studio错误。java无法解析符号com。谷歌。安卓   java Godaddy JNDI问题无法为连接URL“null”创建类“”的JDBC驱动程序   javascript无法打开到同一SockJS端点的多个连接   如何从JAVA中现有的XML节点生成新的XML   java SectionsPagerAdapter找不到片段id的视图   java通过列表一次打印出一个字符