-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
61 lines (45 loc) · 2.11 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import unicode_literals
from time import strftime
def init():
with open("latest.log", "w") as file:
file.write(f"\n -- Log started at {strftime(f'[%Y-%m-%d %H:%M:%S]')} -- \n\n")
with open("latest_ffmpeg.log", "w") as file:
file.write(f"\n -- Log started at {strftime(f'[%Y-%m-%d %H:%M:%S]')} -- \n\n")
with open("latest_ytdl.log", "w") as file:
file.write(f"\n -- Log started at {strftime(f'[%Y-%m-%d %H:%M:%S]')} -- \n\n")
def log(string, BeforeTimestamp = ""): # Need this to work with datetime correctly for an accurate log
string = strftime(f"{BeforeTimestamp}[%Y-%m-%d %H:%M:%S] {string}")
print(string)
with open("latest.log", "a") as file:
file.write(f"{string} \n")
def end(EndByError = False, error = ""):
if EndByError == True:
log(f"Error: {error}")
with open("latest.log", "a") as file:
file.write(f"\n -- Log ended at {strftime(f'[%Y-%m-%d %H:%M:%S]')} -- \n")
with open("latest_ffmpeg.log", "a") as file:
file.write(f"\n -- Log ended at {strftime(f'[%Y-%m-%d %H:%M:%S]')} -- \n")
class ffmpeg:
def log(string):
time = strftime(f'[%Y-%m-%d %H:%M:%S]')
string = f" {time} \n\n{string}\n\n\n"
# print(string)
with open("latest_ffmpeg.log", "a") as file:
file.write(f"{string} \n")
class ytdl(object):
def debug(self, msg):
string = f"{strftime(f'[%Y-%m-%d %H:%M:%S]')} [Debug] {msg}"
print(string, end="\r")
# Causes spam whenn downloading
# with open("latest_ytdl.log", "a") as file:
# file.write(f"{string} \n")
def warning(self, msg):
string = f"{strftime(f'[%Y-%m-%d %H:%M:%S]')} [Warn] {msg}"
print(string)
with open("latest_ytdl.log", "a") as file:
file.write(f"{string} \n")
def error(self, msg):
string = f"{strftime(f'[%Y-%m-%d %H:%M:%S]')} [Error] {msg}"
print(string)
with open("latest_ytdl.log", "a") as file:
file.write(f"{string} \n")