ロギング

Pythonのログ管理についてまとめました。

サンプル

ログをコンソールに出力する

ログをログファイルに出力する

├─log
│      sample_function1.log

====================================
  2022-08-19 15:38:49,392 - DEBUG - python_sample_0035_2.py - function1 - this is debug
  2022-08-19 15:38:49,393 - CRITICAL - python_sample_0035_2.py - function1 - this is critical

ログファイルに容量上限を設けてローテーションする

├─log
│      sample_function1.log
│      sample_function1.log.1
│      sample_function1.log.2
│      sample_function1.log.3

====================================
  2022-08-19 15:38:49,392 - DEBUG - python_sample_0035_2.py - function1 - this is debug
  2022-08-19 15:38:49,393 - CRITICAL - python_sample_0035_2.py - function1 - this is critical
  ・
  ・
  ・