-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.py
46 lines (35 loc) · 1.15 KB
/
Logging.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
# MiSaSiM MIPS ISA Simulator
# Written by Linda and Scott Wills
# (c) 2004-2012 Scott & Linda Wills
#
# Modification for multi-core by Xiao Yu, [email protected]
import sys
class StdoutBackend:
def Print_Message(Self, String):
sys.stdout.write(String)
class Logger:
def __init__(Self, Name):
Self.Name = Name
Self.Backend = StdoutBackend()
def info(Self, Msg):
InfoMsg = '[%s, %s] %s\n' %('INFO', Self.Name, Msg)
Self.Backend.Print_Message(InfoMsg)
def warn(Self, Msg):
WarnMsg = '[%s, %s] %s\n' %('WARN', Self.Name, Msg)
Self.Backend.Print_Message(WarnMsg)
def error(Self, Msg):
ErrorMsg = '[%s, %s] %s\n' %('ERROR', Self.Name, Msg)
Self.Backend.Print_Message(ErrorMsg)
def Config(Self, Backend=StdoutBackend()):
Self.Backend = Backend
def CopyConfig(Self, Other):
Self.Backend = Other.Backend
RootLogger = Logger('')
Loggers = {'' : RootLogger}
class LogFactory:
@classmethod
def getLogger(Cls, Name):
NewLogger = Logger(Name)
NewLogger.CopyConfig(RootLogger)
Loggers[Name] = NewLogger
return NewLogger