-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathlogger.py
62 lines (38 loc) · 1.48 KB
/
logger.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import logging
import logging.config
import os
_INIT_LOGGER = True
def init_logger():
"""Initialize the Logger instance."""
# pylint: disable=W0603
global _INIT_LOGGER
this_dir, _ = os.path.split(__file__)
path = os.path.join(this_dir, "logging.conf")
# See
# https://docs.python.org/3.5/library/logging.config.html#logging.config.fileConfig
# for a discussion of why or why not to set disable_existing_loggers
# to False. The long and short of it is that if you don't set it to
# False it ruins external module's abilities to use the logging
# facility.
logging.config.fileConfig(path, disable_existing_loggers=False)
# Only initialize the logger once.
_INIT_LOGGER = False
def get_logger():
"""Return a Logger instance appropriate for using in a Tap or a Target."""
if _INIT_LOGGER:
init_logger()
return logging.getLogger()
def log_debug(msg, *args, **kwargs):
get_logger().debug(msg, *args, **kwargs)
def log_info(msg, *args, **kwargs):
get_logger().info(msg, *args, **kwargs)
def log_warning(msg, *args, **kwargs):
get_logger().warning(msg, *args, **kwargs)
def log_error(msg, *args, **kwargs):
get_logger().error(msg, *args, **kwargs)
def log_critical(msg, *args, **kwargs):
get_logger().critical(msg, *args, **kwargs)
def log_fatal(msg, *args, **kwargs):
get_logger().fatal(msg, *args, **kwargs)
def log_exception(msg, *args, **kwargs):
get_logger().exception(msg, *args, **kwargs)