log出力に現在時刻を含める
log出力に現在時刻を追加したかった。
formatterに"%(asctime)s"を渡せば良い。
https://docs.python.org/2.7/library/logging.html#logging.Logger.debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import logging | |
logger = logging.getLogger(__name__) | |
FORMAT = '%(asctime)-15s %(message)s' | |
logging.basicConfig(level=logging.DEBUG, format=FORMAT) | |
logger.debug('This message should go to the log file') | |
logger.info('So should this') | |
logger.warning('And this, too') |
出力結果
2014-11-10 09:17:46,154 This message should go to the log file 2014-11-10 09:17:46,154 So should this 2014-11-10 09:17:46,154 And this, too