6
Logging.configファイルでTimedRotatingFileHandlerを使用してテストしようとしていますが、複雑ではありませんが、10秒ごとに新しいログファイルにロールオーバーする必要があります。私は取得していますがlogging.configでTimedRotatingFileHandlerのログを使用する
次
Traceback (most recent call last):
File "testLogging.py", line 6, in <module>
logging.config.fileConfig(logDir+'logging.conf')
File "C:\Python26\Lib\logging\config.py", line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File "C:\Python26\Lib\logging\config.py", line 159, in _install_handlers
h = klass(*args)
File "C:\Python26\Lib\logging\handlers.py", line 195, in __init__
raise ValueError("You must specify a day for weekly rollover from 0 to 6 (0
is Monday): %s" % self.when)
ValueError: You must specify a day for weekly rollover from 0 to 6 (0 is Monday)
: WHEN='S'
Pythonはそれだけで継続的に
import logging
import logging.config
logDir = "./logs/"
logging.config.fileConfig(logDir+'logging.conf')
logger = logging.getLogger('root')
while 1==1:
logger.info('THIS IS AN INFO MESSAGE')
をログに記録し、無限ループと設定ファイルを非常に単純設定され
[loggers]
keys=root
[logger_root]
level=INFO
handlers=timedRotatingFileHandler
[formatters]
keys=timedRotatingFormatter
[formatter_timedRotatingFormatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s
datefmt=%m-%d %H:%M
[handlers]
keys=timedRotatingFileHandler
[handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=INFO
formatter=timedRotatingFormatter
args=('./logs/log.out', 'when=\'S\'', 'interval=10', 'backupCount=5')
あなたが 'S'に設定されていることがわかるように、 'W'ではなく、エラーメッセージが表示されているようです。
編集:ログの設定で正しい構文以下の答えを1としては
args=('./logs/log.out', 'S', 10, 5, None, False, False)
を試してみて、私が思うに、動作するはずです。忘れないでください - args内にあるものは効果的に 'eval()'に渡されます。あなたの最初の提案がうまくいくかどうかはわかりません - 私はそれが 'SyntaxError'を発生させると期待しています。 –
おかげさまで、私は文字通り自分でこれを作業しました。これは正しく機能する最後のフォームでした – PDStat