-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateLogger.py
executable file
·61 lines (48 loc) · 2.23 KB
/
updateLogger.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
#!/usr/bin/env python
########################################################################################################################
# Simple Logging System for the Update Daemon #
########################################################################################################################
# (C) Manuel Bernal Llinares <[email protected]>#
# Distributed under the Apache License 2.0 #
########################################################################################################################
import os
import logging
import updateSettings as settings # Get the settings singleton that should have already been initialized
_logger = None
def getLogger():
global _logger
if not _logger:
# print("Preparing logger")
# Instantiate the _logger
config = settings.getConfig()
# Create the logger
_logger = logging.getLogger(config["logger"]["namespace"])
# Set formatter
formatter = logging.Formatter('[%(asctime)s][%(levelname)s] - %(name)s --- %(message)s')
# Set logger handler
handler = logging.FileHandler(config["logger"]["filePath"])
handler.setFormatter(formatter)
# Set logging level
if "level" in config["logger"]:
if "debug" in config["logger"]["level"]:
handler.setLevel(logging.DEBUG)
elif "critical" in config["logger"]["level"]:
handler.setLevel(logging.CRITICAL)
elif "error" in config["logger"]["level"]:
handler.setLevel(logging.ERROR)
elif "fatal" in config["logger"]["level"]:
handler.setLevel(logging.FATAL)
elif "warning" in config["logger"]["level"]:
handler.setLevel(logging.WARNING)
else:
handler.setLevel(logging.INFO)
else:
handler.setLevel(logging.INFO)
_logger.setLevel(handler.level)
# Add handler to logger
_logger.addHandler(handler)
return _logger # logging.getLogger(settings.getConfig()["logger"]["namespace"])
def main():
print("This module is not designed to play alone. Sorry.")
if __name__ == "__main__":
main()