def set_log(level, filename='jumpserver.log'):
 log_file = os.path.join(LOG_DIR, filename)
 if (not os.path.isfile(log_file)):
  os.mknod(log_file)
  os.chmod(log_file, 511)
 log_level_total = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARN, 'error': logging.ERROR, 'critical': logging.CRITICAL}
 logger_f = logging.getLogger('jumpserver')
 logger_f.setLevel(logging.DEBUG)
 fh = logging.FileHandler(log_file)
 fh.setLevel(log_level_total.get(level, logging.DEBUG))
 formatter = logging.Formatter('%(asctime)s - %(filename)s - %(levelname)s - %(message)s')
 fh.setFormatter(formatter)
 logger_f.addHandler(fh)
 return logger_f

def set_log ( level , filename = 'jumpserver.log' ) : log_file = os . path . join ( LOG_DIR , filename ) if ( not os . path . isfile ( log_file ) ) : os . mknod ( log_file ) os . chmod ( log_file , 511 ) log_level_total = { 'debug' : logging . DEBUG , 'info' : logging . INFO , 'warning' : logging . WARN , 'error' : logging . ERROR , 'critical' : logging . CRITICAL } logger_f = logging . getLogger ( 'jumpserver' ) logger_f . setLevel ( logging . DEBUG ) fh = logging . FileHandler ( log_file ) fh . setLevel ( log_level_total . get ( level , logging . DEBUG ) ) formatter = logging . Formatter ( '%(asctime)s - %(filename)s - %(levelname)s - %(message)s' ) fh . setFormatter ( formatter ) logger_f . addHandler ( fh ) return logger_f
return a log file object 根据提示设置log打印 .