1
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?

pythonのlog出力ベストプラクティス(?)

Posted at

メインの実行ファイルでの記述

main.py
import logging

# ログの設定
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# ロガーの作成
logger = logging.getLogger(__name__)

# ログ出力例
logger.info('This is main.')

メインの実行ファイル以外での記述

my_module.py
import logging

# ロガーの作成
logger = logging.getLogger(__name__)

# ログ出力例
logger.info('This is another module.')

# 他の処理...

※ 全てのファイルに書く

出力例

>>> logger.info('Hello!')
2024-03-04 17:02:09,446 - __main__ - INFO - Hello!
1
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
1
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?