-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
39 lines (37 loc) · 1.43 KB
/
logger.py
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
import time
import datetime
from isobot.colors import Colors
class Logger(Colors):
"""The library used for logging information.
Valid commands:
- info(text)
- warn(text)
- error(text)"""
def __init__(self, log_path:str, error_path:str):
self.log_path = log_path
self.error_path = error_path
print(f"[Framework/Loader] {Colors.green}Logger initialized.{Colors.end}")
def info(self, text:str, *, nolog=False):
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(f'[{current_time}/INFO] {text}')
if nolog == True: pass
else:
with open(self.log_path, 'a') as f:
f.write(f'[{current_time}/INFO] {text}\n')
f.close()
def warn(self, text:str, *, nolog=False):
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(f'[{current_time}/WARN] {text}')
if nolog == True: pass
else:
with open(self.log_path, 'a') as f:
f.write(f'[{current_time}/WARN] {text}\n')
f.close()
def error(self, text:str, *, nolog=False):
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(f'{Colours.red}[{current_time}/ERROR] {text}{Colours.end}')
if nolog == True: pass
else:
with open(self.error_path, 'a') as f:
f.write(f'[{current_time}/ERROR] {text}\n')
f.close()