-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll.py
More file actions
64 lines (47 loc) · 1.6 KB
/
scroll.py
File metadata and controls
64 lines (47 loc) · 1.6 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys
import logging
from os import path
from datetime import datetime
from collections import deque
from parameters import Parameter as P
class Scroll(deque):
def __init__(self, *args, **kwargs):
self.logger = Logger.logger
super().__init__(*args, **kwargs)
def append(self, line):
if P.LOGGING_ENABLED:
self.logger.info(line)
super().append(line)
class Logger:
logger = None
def setup_logging():
"""
Using this makes the program looks a little less printy everywhere.
Instead of using python's logger module, this seemed more clean.
"""
if not P.LOGGING_ENABLED:
return
logging.basicConfig(
level=logging.DEBUG, # Set the logging level to DEBUG to capture all messages
format='%(message)s',
handlers=[logging.FileHandler(P.LOG_FILE_PATH, mode='a')] # Append mode
)
logger = logging.getLogger('teer')
os.chdir(P.SCRIPT_DIR)
log_file = path.abspath(P.LOG_FILE_PATH)
try:
os.makedirs(path.dirname(log_file), exist_ok=True)
user_login = f'{os.getlogin()}@{os.uname()[1]}'
sys_args = ' '.join(sys.argv)
header = f'\n\n[{user_login}] {datetime.now()}\n{sys_args}\n'+'-'*100 + '\n'
logger.info(header)
Logger.logger = logger
except Exception as e:
print(e)
exit(2)
@staticmethod
def print_log_path():
if not P.LOGGING_ENABLED:
return
print(f"\nLogs: {P.LOG_FILE_PATH}")