python自動化テストスクリプト追加ログ
1049 ワード
# -*- coding: utf-8 -*-
__author__ = 'mumu'
import logging
class Config(object):
# logger
logger = logging.getLogger('BB ')
if not logger.handlers:
# handler,
fh = logging.FileHandler('/home/mi/bigbi/test_log/log_file.log')
fh.setLevel(logging.DEBUG)
# handler, %(asctime)s - %(name)s - %(levelname)s - %(message)s
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# handler ( '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# logger handler
logger.addHandler(fh)
logger.addHandler(ch)
logger.setLevel(logging.DEBUG)
# logger.setLevel(logging.ERROR)
def getlog(self):
return self.logger
このような書き方を参考にすることができます