File size: 1,291 Bytes
3494c6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pathlib import Path

import logging
import os

import yaml


def get_handler(path, log_name):
    log_file_path = os.path.join(path, log_name)
    try:
        if not os.path.exists(path):
            print("We are creating the logger files")
            os.makedirs(path)
    except:
        pass
    file_handler = logging.FileHandler(log_file_path)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))

    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(logging.DEBUG)
    stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
    return file_handler, stream_handler


# def get_run_dir(dir_name):
#
#     alg_dir = RESULTS_DIR / dir_name
#     if alg_dir.exists():
#         id_list = [
#             int(str(x).split("_")[-1])
#             for x in alg_dir.iterdir()
#             if str(x).split("_")[-1].isnumeric()
#         ]
#         run_id = 0 if not id_list else max(id_list) + 1
#     else:
#         run_id = 0
#     run_dir = RESULTS_DIR / dir_name / f"run_{str(run_id).zfill(3)}"
#     run_dir.mkdir(parents=True, exist_ok=True)
#     print(f"Results will be stored at {run_dir}")
#
#     return run_dir