[Python] 2.3のメモ書き
移転しました。
標準出力へのログ指定方法 2.3
※ 2.3で標準出力へのログの出し方で、ちょっと時間かかったためメモ
import logging log = logging.getLogger() log.setLevel(logging.DEBUG) handler = logging.StreamHandler(sys.stdout) fmt = logging.Formatter('%(levelname)s %(message)s') handler.setFormatter(fmt) log.addHandler(handler) log.debug('A debug message') log.info('Some information') log.warning('A shot across the bows')
2.5だと
import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename='/tmp/myapp.log', filemode='w') logging.debug('A debug message') logging.info('Some information') logging.warning('A shot across the bows')