Demo

import logging
import sys

logging.basicConfig(filename='./test.log', filemode='a', level=logging.INFO,
                    format='%(asctime)s %(message)s', datefmt='%H:%M:%S')
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(sys.stdout))

logger.info('this is a test log')

Reference

  1. Logging facility for Python
  2. python logging模块
  3. python中logging日志模块详解