-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.py
32 lines (24 loc) · 1.01 KB
/
log.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
from datetime import datetime as dt
import os
__main_path__ = os.path.dirname(__file__)
def nowing():
return dt.now().timestamp()
class log:
def __init__(self, title:str, mess:str):
if os.path.exists(path=f'{__main_path__}/DATA/loging.log'):
self.log = open(f'{__main_path__}/DATA/loging.log', 'a+', encoding='utf8')
self.title = title
self.mess = mess
self.log_list = self.log.read().split('\n')
else:
try:
os.makedirs(f'{__main_path__}/DATA/')
except FileExistsError:
pass
self.log = open(f'{__main_path__}/DATA/loging.log', 'a+', encoding='utf8')
self.title = title
self.mess = mess
self.log_list = self.log.read().split('\n')
def write_message(self, time=True):
if time: self.log.write(f"\n[{self.title}|({nowing()})] {self.mess}")
else: self.log.write(f"\n[{self.title}] {self.mess}")