Python で syslog へのログ記録を設定するにはどうすればいいですか? 質問する

Python で syslog へのログ記録を設定するにはどうすればいいですか? 質問する

Python のモジュールが理解できませんlogging。私のニーズは非常にシンプルです。すべてを syslog に記録したいだけです。ドキュメントを読んだ後、次の簡単なテスト スクリプトを思いつきました。

import logging
import logging.handlers

my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler()

my_logger.addHandler(handler)

my_logger.debug('this is debug')
my_logger.critical('this is critical')

しかし、このスクリプトは syslog にログ レコードを生成しません。何が問題なのでしょうか?

ベストアンサー1

この行を次のように変更します。

handler = SysLogHandler(address='/dev/log')

これは私には有効です

import logging
import logging.handlers

my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler(address = '/dev/log')

my_logger.addHandler(handler)

my_logger.debug('this is debug')
my_logger.critical('this is critical')

おすすめ記事