File size: 610 Bytes
44db343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os


class Logger():
    def __init__(self, fname):
        path, _ = os.path.split(fname)
        os.makedirs(path, exist_ok=True)

        self.logger = open(fname, 'w+', encoding='utf-8')

    def log(self, string, file_only = False):
        if not file_only:
            print(string)
        self.logger.write(string+'\n')
        self.logger.flush()

    def close(self):
        self.logger.close()

LOGGER = dict()

def get_logger(path = ""):
    global LOGGER
    try:
        logger = LOGGER[path]
    except:
        logger = Logger(path)
        LOGGER[path] = logger
    
    return logger