Update tests/pynamics-logger.py
This commit is contained in:
@@ -8,58 +8,66 @@
|
|||||||
#6: perf_smpl
|
#6: perf_smpl
|
||||||
#7: get_time
|
#7: get_time
|
||||||
#8: breakpoint
|
#8: breakpoint
|
||||||
verboseness = 7
|
class PynamicsLogger:
|
||||||
lvldict = {
|
def __init__(self):
|
||||||
0: "FATAL",
|
self.verboseness = 7
|
||||||
1: "ALERT",
|
self.lvldict = {
|
||||||
2: "CRIT",
|
0: "FATAL",
|
||||||
3: "ERR",
|
1: "ALERT",
|
||||||
4: "WARNING",
|
2: "CRIT",
|
||||||
5: "NOTICE",
|
3: "ERR",
|
||||||
6: "INFO",
|
4: "WARNING",
|
||||||
7: "DEBUG"
|
5: "NOTICE",
|
||||||
}
|
6: "INFO",
|
||||||
stpwtchtime = StopWatch()
|
7: "DEBUG"
|
||||||
stpwtchtime.pause()
|
}
|
||||||
|
self.time = StopWatch()
|
||||||
|
self.time.pause()
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
stpwtchtime.reset()
|
self.time.reset()
|
||||||
stpwtchtime.resume()
|
self.time.resume()
|
||||||
|
|
||||||
def log(self, message, level, origin):
|
def log(self, message, level, origin):
|
||||||
if level <= verboseness:
|
if level <= self.verboseness:
|
||||||
ms = stpwtchtime.time()
|
ms = self.time.time()
|
||||||
timestamp = "{:02d}:{:02d}.{:03d}".format(
|
timestamp = "{:02d}:{:02d}.{:03d}".format(
|
||||||
(ms // 60000) % 60,
|
(ms // 60000) % 60,
|
||||||
(ms // 1000) % 60,
|
(ms // 1000) % 60,
|
||||||
ms % 1000
|
ms % 1000
|
||||||
)
|
)
|
||||||
label = lvldict.get(level, "UNKNOWN")
|
label = self.lvldict[level]
|
||||||
padding = " " * (7 - len(label))
|
padding = " " * (7 - len(label))
|
||||||
print("[{}] {}{} [{}] {}".format(timestamp, label, padding, origin, message))
|
print(f"[{timestamp}] [{label}]{padding} [{origin}] {message}")
|
||||||
|
|
||||||
def sendCommand(eventnum, level, msg, origin):
|
def sendCommand(self, eventnum, level, msg, origin):
|
||||||
print(f"\x1b[?PYN;{str(eventnum)};{lvldict[level]};{msg}~")
|
print(f"\x1b[?PYN;{str(eventnum)};{lvldict[level]};{msg}~")
|
||||||
def notify(level, msg, origin):
|
def notify(level, msg, origin):
|
||||||
print(f"\x1b[?PYN;0;{lvldict[level]};{msg}~")
|
self.sendCommand(self, 0, level, msg, origin)
|
||||||
def fatal(self, message, origin): notify(message, 0, origin)
|
def notifyfatal(self, message, origin): notify(message, 0, origin)
|
||||||
def alert(self, message, origin): notify(message, 1, origin)
|
def notifyalert(self, message, origin): notify(message, 1, origin)
|
||||||
def crit(self, message, origin): notify(message, 2, origin)
|
def notifycrit(self, message, origin): notify(message, 2, origin)
|
||||||
def err(self, message, origin): notify(message, 3, origin)
|
def notifyerr(self, message, origin): notify(message, 3, origin)
|
||||||
def warning(self, message, origin): notify(message, 4, origin)
|
def notifywarning(self, message, origin): notify(message, 4, origin)
|
||||||
def notice(self, message, origin): notify(message, 5, origin)
|
def notifynotice(self, message, origin): notify(message, 5, origin)
|
||||||
def info(self, message, origin): notify(message, 6, origin)
|
def notifyinfo(self, message, origin): notify(message, 6, origin)
|
||||||
def debug(self, message, origin): notify(message, 7, origin)
|
def notifydebug(self, message, origin): notify(message, 7, origin)
|
||||||
def crash(self, message, origin):
|
def notifycrash(self, message, origin):
|
||||||
sendCommand(3, 0, "uhhhh so the program kinda crashed sorry", origin)
|
sendCommand(3, 0, "uhhhh so the program kinda crashed sorry", origin)
|
||||||
raise FatalLoggerError("[FATAL] [{}] {}".format(origin, message))
|
raise FatalLoggerError("[FATAL] [{}] {}".format(origin, message))
|
||||||
sendCommand(0, 0, "hey you should probably know that your RAM is corrupted and you cant replace it because of the shortage. byeeeee", "test prgm")
|
|
||||||
sendCommand(0, 1, "UNRECOVERABLE PYTHON ERROR!!!!! Exiting gracefully... JUST KIDDING WHAT DID YOU THINK IT WAS GONNA DO", "test prgm")
|
def breakpoint(self, message, origin):
|
||||||
sendCommand(0, 2, "so the program is running but it just started looping on the motor frying bit of your program.", "test prgm")
|
sendCommand(3, 8, "currently everything about the robot")
|
||||||
sendCommand(0, 3, "syntax error, you failure!!!! use an error checker", "test prgm")
|
def testAll(self):
|
||||||
sendCommand(0, 4, "wanted to just say that your motor is kinda being slow", "test prgm")
|
self.start()
|
||||||
sendCommand(0, 5, "so your motor is like 1% slower than it should be but really no one cares", "test prgm")
|
notifyfatal("hey you should probably know that your RAM is corrupted and you cant replace it because of the shortage. byeeeee", "test prgm")
|
||||||
sendCommand(0, 6, "hey everything in the program is going well just in case nothing in your life is", "test prgm")
|
notifyalert(0, 1, "UNRECOVERABLE PYTHON ERROR!!!!! Exiting gracefully... JUST KIDDING WHAT DID YOU THINK IT WAS GONNA DO", "test prgm")
|
||||||
sendCommand(0, 7, "nobody cares about me but you should know that", "test prgm")
|
notifycrit(0, 2, "so the program is running but it just started looping on the motor frying bit of your program.", "test prgm")
|
||||||
def breakpoint():
|
notifyerr(0, 3, "syntax error, you failure!!!! use an error checker", "test prgm")
|
||||||
#send a command 8 and also get all important info about the code here and print
|
notifywarning(0, 4, "wanted to just say that your motor is kinda being slow", "test prgm")
|
||||||
|
notifynotice(0, 5, "so your motor is like 1% slower than it should be but really no one cares", "test prgm")
|
||||||
|
notifyinfo(0, 6, "hey everything in the program is going well just in case nothing in your life is", "test prgm")
|
||||||
|
notifydebug(0, 7, "nobody cares about me but you should know that", "test prgm")
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pynlogger = PynamicsLogger()
|
||||||
|
pynlogger.testAll()
|
||||||
|
|||||||
Reference in New Issue
Block a user