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()所接受的指定日期/时间格式
    styleIf 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指定根日志记录器级别
    streamUse the specified stream to initialize the StreamHandler. Note that this argument is incompatible with filename - if both are present, a ValueError is raised.
    handlersIf 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.
  • 8
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值