0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Jupyter Tips

Posted at

ログの重複出力抑止

Jupyterではルートロガーにハンドラーが設定されてるので、
子ロガーにハンドラーを設定しログ出力すると、ルートロガーに伝搬し、ルートロガーのハンドラーでも出力される。(子ロガーとルートロガーで重複出力される)

これを防ぐにはlogger.propagete=Falseを設定すればいい

from logging import getLogger,DEBUG

logger = getLogger(<logger name>) # 子ロガー取得
logger.propergate = False # 親ロガーへの伝搬抑止
logger.setLevel(DEBUG)
if not logger.hasHandlers():
    logger.addHandler(<your handler>)
logger.debug("Hello World")

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?