logging.basicConfig()详解

  1. Python中logging模块详解
  2. logging.addLevelName()添加自定义级别
  3. logging.basicConfig()详解
  • logging.basicConfig(**kwargs)
    

    此函数,通过创建一个带有默认 FormatterStreamHandler 并将其添加到根日志记录器中来初始化基本配置。如果根日志记录器没有定义处理器,则debug(), info(), warning(), error() and critical() 会自动调用 basicConfig()

    如果根日志记录器已经配置了处理器,则此函数不起作用。

    此函数应该在主线程中调用,且在其他线程开始之前。在Python2.7.1和3.2之前,此函数被多线程调用。有可能(极少数)处理器会被多次添加到根日志记录器,导致意外结果比如日志中信息重复。

    支持以下关键字参数:

    格式 描述
    filename 说明创建了一个名为filename的FileHandler,而非StreamHandler
    filemode 如果指定了filename参数,则以此模式打开,默认是 'a'.
    format 使用指定字符串格式
    datefmt 使用 time.strftime()所接受的指定日期/时间格式
    style If format is specified, use this style for the format string. One of '%', '{' or '$'for printf-style, str.format() or string.Template respectively. Defaults to '%'.
    level 指定根日志记录器级别
    stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with filename - if both are present, a ValueError is raised.
    handlers If specified, this should be an iterable of already created handlers to add to the root logger. Any handlers which don’t already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible with filename or stream - if both are present, a ValueError is raised.

你可能感兴趣的:(小白学Python)