MCPcopy
hub / github.com/Tencent/NeuralNLP-NeuralClassifier / Logger

Class Logger

util.py:44–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class Logger(object):
45 _instance = None
46
47 def __new__(cls, *args, **kw):
48 if not cls._instance:
49 cls._instance = super(Logger, cls).__new__(cls)
50 return cls._instance
51
52 def __init__(self, config):
53 if config.log.log_level == "debug":
54 logging_level = logging.DEBUG
55 elif config.log.log_level == "info":
56 logging_level = logging.INFO
57 elif config.log.log_level == "warn":
58 logging_level = logging.WARN
59 elif config.log.log_level == "error":
60 logging_level = logging.ERROR
61 else:
62 raise TypeError(
63 "No logging type named %s, candidate is: info, debug, error")
64 logging.basicConfig(filename=config.log.logger_file,
65 level=logging_level,
66 format='%(asctime)s : %(levelname)s %(message)s',
67 filemode="a", datefmt='%Y-%m-%d %H:%M:%S')
68
69 @staticmethod
70 def debug(msg):
71 """Log debug message
72 msg: Message to log
73 """
74 logging.debug(msg)
75 sys.stdout.write(msg + "\n")
76
77 @staticmethod
78 def info(msg):
79 """"Log info message
80 msg: Message to log
81 """
82 logging.info(msg)
83 sys.stdout.write(msg + "\n")
84
85 @staticmethod
86 def warn(msg):
87 """Log warn message
88 msg: Message to log
89 """
90 logging.warning(msg)
91 sys.stdout.write(msg + "\n")
92
93 @staticmethod
94 def error(msg):
95 """Log error message
96 msg: Message to log
97 """
98 logging.error(msg)
99 sys.stderr.write(msg + "\n")

Callers 2

__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected