-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioLogging.py
More file actions
47 lines (37 loc) · 1.33 KB
/
ioLogging.py
File metadata and controls
47 lines (37 loc) · 1.33 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
import time
import subprocess
import iohandlers.default
class Entry:
def __init__(self, module, message, application, command, timestamp):
self.module = module
self.message = message
self.application = application
self.command = command
self.timestamp = timestamp
class Log:
def __init__(self, printHandlers = [iohandlers.default.defaultHandler.handlePrint]):
self.printHandlers = printHandlers
self.history = []
def print(self, module, message, application = "<server>", command = "", timestamp = time.time()):
entry = Entry(
module = module,
message = message,
application = application,
command = command,
timestamp = timestamp
)
self.history.append(entry)
for i in range(0, len(self.printHandlers)):
self.printHandlers[i](entry)
def runCommand(self, module, application, command):
try:
message = subprocess.check_output(command, shell = True, stderr = subprocess.STDOUT).decode("utf-8")
except Exception as e:
message = e.output.decode("utf-8")
self.print(
module = module,
message = message,
application = application,
command = command
)
return message