私はPythonのロギングモジュールでエラーを記録しています。次のように私は、私のクラスの内部でロガーオブジェクトを作った:Pythonのロギングモジュールでのロギングエラーの問題
self.my_logger = logging.getLogger('my_logger')
self.my_logger.setLevel(logging.ERROR)
私のように、後でコードのエラーをログに記録しようとすると:
self.my_logger.error("My error")
その後、私はエラーを取得する:
AttributeError: FileHandler instance has no attribute 'filters'
詳細なエラー・ログには、次のとおりです。
File "/lib/python2.6/logging/__init__.py", line 1047, in error
self._log(ERROR, msg, args, **kwargs)
File "/lib/python2.6/logging/__init__.py", line 1129, in _log
self.handle(record)
File "/lib/python2.6/logging/__init__.py", line 1139, in handle
self.callHandlers(record)
File "/lib/python2.6/logging/__init__.py", line 1176, in callHandlers
hdlr.handle(record)
File "/lib/python2.6/logging/__init__.py", line 658, in handle
rv = self.filter(record)
File "/lib/python2.6/logging/__init__.py", line 558, in filter
for f in self.filters:
AttributeError: FileHandler instance has no attribute 'filters'
if self.log_dir != None:
self.log_filename = os.path.join(self.log_dir, 'run.%s' \
%(time.strftime("%m-%d-%y_%H:%M:%S")))
ch_file = logging.FileHandler(self.log_filename,
delay=True)
ch_file.setLevel(logging.ERROR)
ch_file.setFormatter(formatter)
self.my_logger.addHandler(ch_file)
ch_stream = logging.StreamHandler()
ch_stream.setLevel(logging.INFO)
# add formatter to ch
ch_stream.setFormatter(formatter)
# add ch to logger
self.my_logger.addHandler(ch_stream)
self.my_logger.info("Ready.")
ここで何が起こっているかを任意のアイデア:この上流には、ここで私はファイルハンドラを設定する方法ですか?ありがとう。
ロガーにおそらくルートロガーのハンドラーを追加する方法があります。このセットアップコードも表示できますか? –
FileHandlerに問題があるようです。 FileHandler設定を投稿できますか? –
編集済みの投稿に投稿しました。ありがとう – user248237dfsf