Pythonのログ関数の使い方-その2
Level3 リモート端末のファイルにログを出力する
# -*- coding:utf-8 -*- import logging logging.basicConfig( # ログレベルを指定 level=logging.DEBUG, # ログの書式を指定 左から時刻、ログレベル、モジュール名、関数名、行数、内容 format="%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d %(message)s") def test(): logging.error('error!') logging.debug('debug!') test()
実行結果
コンソールに書式指定の通りに表示されます。
# python log.py 2014-10-15 14:19:32,155 ERROR log test 12 error! 2014-10-15 14:19:32,155 DEBUG log test 13 debug!