google / ml_collections

ML Collections is a library of Python Collections designed for ML use cases.
https://ml-collections.readthedocs.io/
Apache License 2.0
898 stars 42 forks source link

'import ml_collections' and 'import logging' occured a bug. #21

Open JiafengtTang opened 1 year ago

JiafengtTang commented 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.