Repository navigation
Expand file tree
/
Copy pathlogger.py
More file actions
66 lines (56 loc) · 2.02 KB
/
Copy pathlogger.py
File metadata and controls
66 lines (56 loc) · 2.02 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
65
66
# file and command prompt colorama logger
from . import config
import os, time, threading
from colorama import Fore
class Logger:
init = False
write_lock = threading.Lock()
last_error = None
def warning(msg):
Logger._write(Fore.YELLOW, msg)
def error(msg):
Logger.last_error = msg
Logger._write(Fore.RED, msg)
def ok(msg):
Logger._write(Fore.GREEN, msg)
def info(msg):
Logger._write(Fore.RESET, msg)
def _write(level, msg):
t = time.strftime('%b %d, %Y %X')
if os.name == 'nt' and config.IS_SERVICE:
Logger._windows_log(level, msg)
else:
with Logger.write_lock:
with open(os.path.abspath(os.path.join(config.LOG_DIR, config.LOG_FILENAME)), "a") as log_file:
log_file.write("%s : %s\r\n" % (t, msg))
print("%s%s : %s%s" % (level, t, msg, Fore.RESET))
def _windows_log(level, msg):
import win32api
import win32con
import win32evtlog
import win32security
import win32evtlogutil
applicationName = "CryptoBot"
ph = win32api.GetCurrentProcess()
th = win32security.OpenProcessToken(ph, win32con.TOKEN_READ)
my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
category = 5 # arbitrary value
msg = str(msg)
if level == Fore.YELLOW:
eventID = 2
myType = win32evtlog.EVENTLOG_WARNING_TYPE
descr = [msg]
elif level == Fore.RED:
eventID = 3
myType = win32evtlog.EVENTLOG_ERROR_TYPE
descr = [msg]
elif level == Fore.GREEN:
eventID = 0
myType = win32evtlog.EVENTLOG_SUCCESS
descr = [msg]
else:
eventID = 1
myType = win32evtlog.EVENTLOG_INFORMATION_TYPE
descr = [msg]
win32evtlogutil.ReportEvent(applicationName, eventID, eventCategory=category,
eventType=myType, strings=descr, sid=my_sid)