/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def setupLogger(self, log_dir): if not isdir(log_dir): os.mkdir(log_dir) # create logger log_file = join(log_dir, time.strftime('%Y_%m_%d') + '.log') logger = logging.getLogger(log_file) logger.setLevel(logging.INFO) # create console handler and set level to debug ch = logging.FileHandler(log_file) ch.setLevel(logging.INFO) # create formatter formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") # add formatter to ch ch.setFormatter(formatter) # add ch to logger logger.addHandler(ch) return logger