def create_log(self, log_path=None, log_level='DEBUG'):
"""Create a log file for debug output.
Args:
log_path: Path to log file. If None or empty
the log path name will be the
command line invocation name (argv[0]) with
a '.log' suffix in the user's home directory.
log_level: Log level:
'DEBUG', 'INFO', 'WARNING', 'ERROR', or 'CRITICAL'.
Default is 'DEBUG'.
"""
if log_path is None or not log_path:
log_dir = os.path.expanduser('~')
log_path = os.path.join(log_dir, sys.argv[0] + '.log')
log_path = os.path.expanduser(log_path)
logging.basicConfig(filename=os.path.abspath(log_path),
filemode='w', level=log_level.upper())
logger = logging.getLogger(__name__)
logger.info('Log started %s, level=%s', datetime.datetime.now(),
logging.getLevelName(logger.getEffectiveLevel()))
评论列表
文章目录