-
Notifications
You must be signed in to change notification settings - Fork 0
/
MQTT4DSF_Logging.py
49 lines (40 loc) · 1.92 KB
/
MQTT4DSF_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
#!/usr/bin/env python3
import logging
import os
import sys
import time
import datetime
import signal
import json
class MQTTDSF_Logging:
SETTINGS_FILE = "/opt/dsf/sd/sys/MQTT4DSF_Config.json"
def __init__(self):
self._load_settings()
self._log_setup()
def _load_settings(self):
with open(self.SETTINGS_FILE) as json_settings:
settings = json.load(json_settings)
self.s_MQTT4DSF_Logging_level = str(settings["GENERAL_SETTINGS"]["MQTT4DSF_SYSTEM_LOGGING_LEVEL"])
def _log_setup(self):
logging.basicConfig(filename='/var/log/MQTT4DSF.log',
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt='%H:%M:%S',
level=logging.INFO)
#logging.WARNING("Started The Log")
self.log = logging.getLogger("MQTT4DSF")
self.log.warning("Started the Log")
self._change_logging_level()
def _change_logging_level(self):
self.log.warning("Changing Log Level to = " + str(self.s_MQTT4DSF_Logging_level))
if self.s_MQTT4DSF_Logging_level == "DEBUG": self.log.setLevel(logging.DEBUG)
if self.s_MQTT4DSF_Logging_level == "INFO": self.log.setLevel(logging.INFO)
if self.s_MQTT4DSF_Logging_level == "CRITICAL": self.log.setLevel(logging.CRITICAL)
if self.s_MQTT4DSF_Logging_level == "WARNING": self.log.setLevel(logging.WARNING)
if self.s_MQTT4DSF_Logging_level == "ERROR": self.log.setLevel(logging.ERROR)
def AddLogEntry(self, sloglevel, slogtxt):
if sloglevel == "DEBUG": self.log.debug(str(slogtxt))
if sloglevel == "INFO": self.log.info(str(slogtxt))
if sloglevel == "CRITICAL": self.log.critical(str(slogtxt))
if sloglevel == "WARNING": self.log.warning(str(slogtxt))
if sloglevel == "ERROR": self.log.error(str(slogtxt))