CoolFace
Apppublic

HuggingFaceM4/IDEFICS_Data_Measurement_Tool

sourceHugging Faceupdated 3y agoView on Hugging Face
2likes
__init__.py30 linesDownload Raw Back to utils
1import logging2import os3from pathlib import Path4 5 6def prepare_logging(fid):7    # Create the directory for log files (if it doesn't exist)8    Path('./log_files').mkdir(exist_ok=True)9    log_fid = Path(fid).stem10    logs = logging.getLogger(log_fid)11    logs.setLevel(logging.DEBUG)12 13    logs.propagate = False14    log_fid = Path(fid).stem15    if not logs.handlers:16        # Logging info to log file17        file_path = ("./log_files/%s.log" % log_fid)18        print("Logging output in %s " % file_path)19        file = logging.FileHandler(file_path)20        fileformat = logging.Formatter("%(asctime)s:%(pathname)s,  %(module)s:%(lineno)s\n%(message)s")21        file.setLevel(logging.INFO)22        file.setFormatter(fileformat)23        # Logging debug messages to stream24        stream = logging.StreamHandler()25        streamformat = logging.Formatter("[data_measurements_tool] {%(pathname)s:%(lineno)d} %(module)s %(levelname)s - %(message)s")26        stream.setLevel(logging.DEBUG)27        stream.setFormatter(streamformat)28        logs.addHandler(file)29        logs.addHandler(stream)30    return logs