From 29d91b18aab5332603731112ae3760ff609961e8 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 10 Jun 2021 05:56:32 +0200 Subject: [PATCH] Logging to stdout color changes and some general fixes. --- uplink | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/uplink b/uplink index ca56490..fc9c50a 100755 --- a/uplink +++ b/uplink @@ -35,15 +35,15 @@ import time from fritzconnection.lib.fritzstatus import FritzStatus from threading import Thread -__version__ = "0.2" +# Version format: MAJOR.FEATURE.FIXES +__version__ = "0.2.1" logger = logging.getLogger(__name__) PURPLE = "\033[95m" BLUE = "\033[94m" YELLOW = "\033[93m" -GREEN = "\033[92m" -RED = "\033[91m" +GRAY = "\033[90m" END = "\033[0m" @@ -110,7 +110,7 @@ def get_data(config, inc): password=config["database_password"], database=config["database"]) except Exception as err: - logger.error("ERROR: Database connection failed!" + str(err)) + logger.error("Database connection failed: " + str(err)) # see https://stackoverflow.com/questions/1489669/how-to-exit-the-entire-application-from-a-python-thread # maybe the following is better. need to evaluate: # thread.interrupt_main() @@ -124,7 +124,7 @@ def get_data(config, inc): try: fc = FritzStatus(address=config["uplinks"][inc]["ip"], password=config["uplinks"][inc]["password"]) except Exception as err: - logger.error(RED + "ERROR: " + str(err) + " on device with ip:" + config["uplinks"][inc]["ip"] + END) + logger.error(str(err) + " on device with ip: " + config["uplinks"][inc]["ip"]) sql = 'INSERT INTO log (timestamp, date, time, internal_ip, is_linked, is_connected, provider, message, ' \ 'source_host) VALUES (\"' + str(timestamp) + '\",\"' + str(d) + '\",\"' + str(t) + '\",\"' + \ str(config["uplinks"][inc]["ip"]) + '\",\"' + "0" + '\",\"' + "0" + '\",\"' + \ @@ -180,7 +180,7 @@ if __name__ == "__main__": if args.stdout: formatter = logging.Formatter( - BLUE + "%(asctime)s" + END + ":" + PURPLE + "%(levelname)s" + END + ":" + YELLOW + "%(name)s" + END + ":%(message)s") + PURPLE + "%(asctime)s" + END + ":" + BLUE + "%(levelname)s" + END + ":" + YELLOW + "%(name)s" + END + GRAY + ":%(message)s" + END) handler1 = logging.StreamHandler(sys.stdout) handler1.setFormatter(formatter) root_logger.addHandler(handler1) @@ -203,11 +203,11 @@ if __name__ == "__main__": config_data = configfile.read() _config = json.loads(config_data) except Exception as err: - logger.error("ERROR: Reading configuration file '" + config_path + "' failed!: " + str(err)) + logger.error("Reading configuration file '" + config_path + "' failed!: " + str(err)) exit(1) try: run(_config) except KeyboardInterrupt: - logger.info("uplink terminated!") + logger.info("Program terminated!") exit(0)