def get_path(key): config = Config.get_config() data_path = Path(config["base_path"]) / config[key] if not os.path.exists(data_path): os.mkdir(data_path) return data_path
def __init__(self, env=None): if env is None: config_dict = { "base_path": "", "logging_path": "../..", "log_name": "tests", } else: config_dict = Config.get_config(env) today = datetime.today().strftime("%Y%m%d") now = datetime.today().strftime("%Y%m%d_%H%M%S") logger_path = "{}/{}".format( Path(config_dict["base_path"]) / Path(config_dict["logging_path"]), today) # TODO: change below to filesystem connector if not Path(logger_path).exists(): os.makedirs(Path(logger_path), exist_ok=True) name = config_dict["log_name"].replace(" ", "_") if os.getenv("LOG_NAME"): name = os.getenv("LOG_NAME").replace(" ", "_") log_filename = "{}/{}_{}.log".format(logger_path, now, name) stdout_handler = logging.StreamHandler(sys.stdout) stdout_filter = SingleLevelFilter(logging.INFO, False) stdout_handler.addFilter(stdout_filter) stderr_handler = logging.StreamHandler(sys.stderr) stderr_filter = SingleLevelFilter(logging.INFO, True) stderr_handler.addFilter(stderr_filter) logging.basicConfig( level=logging.INFO, format= "%(asctime)s - %(threadName)s - [%(levelname)s] - %(message)s", handlers=[ stdout_handler, stderr_handler, logging.FileHandler(log_filename), ], ) self.logger_path = log_filename self.logger = logging.getLogger(__name__ + ".logger")