File size: 788 Bytes
59f797f
 
 
 
 
27f2632
59f797f
 
 
 
 
 
6f9d64a
59f797f
 
 
 
 
6f9d64a
 
59f797f
 
 
 
 
 
 
 
 
 
27f2632
 
 
 
 
 
 
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
import logging
import sys


def get_logger():
    return logging.getLogger(__name__)


def setup_logger():
    # clear log
    file_to_delete = open("log.txt", "w")
    file_to_delete.close()

    file_handler = logging.FileHandler(filename="log.txt")
    stdout_handler = logging.StreamHandler(stream=sys.stdout)
    handlers = [file_handler, stdout_handler]

    logging.basicConfig(
        level=logging.INFO,
        format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s",
        handlers=handlers,
    )

    return get_logger()


def read_logs():
    sys.stdout.flush()
    with open("log.txt", "r") as f:
        return f.read()


def flush_logs():
    sys.stdout.flush()
    # clear log
    file_to_delete = open("log.txt", "w")
    file_to_delete.close()