Open JiafengtTang opened 1 year ago
***run: import ml_collections import os import logging
def get_logger(logpath, filepath, package_files=[], displaying=True, saving=True, debug=False): logger = logging.getLogger(name) if debug: level = logging.DEBUG else: level = logging.INFO logger.setLevel(level) if saving: info_file_handler = logging.FileHandler(logpath, mode="a") info_file_handler.setLevel(level) logger.addHandler(info_file_handler) if displaying: console_handler = logging.StreamHandler() console_handler.setLevel(level) formatter = logging.Formatter('%(asctime)s -- [%(levelname)s] -- %(message)s') # '%(asctime)s - %(name)s - %(levelname)s - %(message)s' console_handler.setFormatter(formatter) logger.addHandler(console_handler) logger.info(filepath) with open(filepath, "r") as f: logger.info(f.read())
for f in package_files: logger.info(f) with open(f, "r") as package_f: logger.info(package_f.read()) return logger
log = get_logger(logpath='../exp/log.txt', filepath=os.path.abspath(file)) log.info('fasd')
***output: 2023-01-13 18:14:09,523 -- [INFO] -- fasd I0113 18:14:09.523282 139717526757952 vit_seg_configs.py:164] fasd The second line of output is garbled.
***run: import ml_collections import os import logging
def get_logger(logpath, filepath, package_files=[], displaying=True, saving=True, debug=False): logger = logging.getLogger(name) if debug: level = logging.DEBUG else: level = logging.INFO logger.setLevel(level) if saving: info_file_handler = logging.FileHandler(logpath, mode="a") info_file_handler.setLevel(level) logger.addHandler(info_file_handler) if displaying: console_handler = logging.StreamHandler() console_handler.setLevel(level) formatter = logging.Formatter('%(asctime)s -- [%(levelname)s] -- %(message)s') # '%(asctime)s - %(name)s - %(levelname)s - %(message)s' console_handler.setFormatter(formatter) logger.addHandler(console_handler) logger.info(filepath) with open(filepath, "r") as f: logger.info(f.read())
log = get_logger(logpath='../exp/log.txt', filepath=os.path.abspath(file)) log.info('fasd')
***output: 2023-01-13 18:14:09,523 -- [INFO] -- fasd I0113 18:14:09.523282 139717526757952 vit_seg_configs.py:164] fasd The second line of output is garbled.