-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
29 lines (22 loc) · 808 Bytes
/
log.py
File metadata and controls
29 lines (22 loc) · 808 Bytes
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
import datetime
import os
class Logger:
@staticmethod
def get_time():
return "{:%S: % M: % H}".format(datetime.datetime.now())
@staticmethod
def get_date():
return "{:%d-%m-%y}".format(datetime.datetime.now())
@staticmethod
def get_time():
return "{:%d-%m-%y %S:%M:%H}".format(datetime.datetime.now())
def __init__(self, folder):
self.log_dir = folder
if not os.path.isdir(self.log_dir):
os.mkdir(folder)
self.date = datetime.date.today()
def print(self, msg: str):
with open(self.log_dir + "{}.log".format(self.get_date()), "a", encoding="UTF-8") as file:
file.write("[{}] {}\n".format(self.get_time(), msg))
file.close()
print("[{}] {}".format(self.get_time(), msg))