2

In log4net we can change the log level in the xml config file on runtime from DEBUG to ERROR for example and the change take effect immediately.

is there a way to do it in python? i haven't figured out yet how to do it.

In addition, for some reason, when the logging file is set without any folder (see example of the config i use at the bottom - yaml dictionary config file), it fails to rotate files. if i change it to be at any other path other the one that the code is in, it works like a charm and 20 files get created. i will be happy to get any help. thanks!

dictionary config extract example:

  rotatingFile:
        class : logging.handlers.RotatingFileHandler
        formatter:  jajahFormater
        level: DEBUG
        filename: chs.log
        maxBytes: 20
        backupCount: 20
4

2 回答 2

1

你真的应该发布两个问题。

  1. 基础设施监视.NET配置文件并自动加载它以获取更改,但 Python 不会 - 因此您需要自己编写代码。
  2. 代码目录中的chs.log文件可能保持打开状态(例如在编辑器中),这将防止翻转 - 如果没有更多信息,我无法判断。
于 2013-07-10T17:09:53.920 回答
0

文档Logger.setLevel()在记录器级别和Handler.setLevel()处理程序级别使用

import logging

my_logger = logging.getLogger('myloggername') #Assumes you have configured the logger somewhere
my_logger.setLevel(logging.INFO)
于 2013-07-10T16:58:38.577 回答