From 83ceb41138a8eea9a18a413652b821f64fcd6b5c Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 29 Nov 2023 14:53:01 -0500 Subject: [PATCH] Add daemon name to Logger entries --- daemon-common/log.py | 21 ++++++++++++++------- node-daemon/pvcnoded/Daemon.py | 3 ++- node-daemon/pvcnoded/util/zookeeper.py | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/daemon-common/log.py b/daemon-common/log.py index 352d8f91..16a27e3f 100644 --- a/daemon-common/log.py +++ b/daemon-common/log.py @@ -76,7 +76,9 @@ class Logger(object): self.config = config if self.config["file_logging"]: - self.logfile = self.config["log_directory"] + "/pvc.log" + self.logfile = ( + self.config["log_directory"] + "/" + self.config["daemon_name"] + ".log" + ) # We open the logfile for the duration of our session, but have a hup function self.writer = open(self.logfile, "a", buffering=0) @@ -139,20 +141,25 @@ class Logger(object): if prefix != "": prefix = prefix + " - " - # Assemble message string - message = colour + prompt + endc + date + prefix + message - # Log to stdout if self.config["stdout_logging"]: - print(message) + # Assemble output string + output = colour + prompt + endc + date + prefix + message + print(output) # Log to file if self.config["file_logging"]: - self.writer.write(message + "\n") + # Assemble output string + output = colour + prompt + endc + date + prefix + message + self.writer.write(output + "\n") # Log to Zookeeper if self.config["zookeeper_logging"]: - self.zookeeper_queue.put(message) + # Set the daemon value (only used here as others do not overlap with different daemons) + daemon = f"{self.config['daemon_name']}: " + # Assemble output string + output = daemon + colour + prompt + endc + date + prefix + message + self.zookeeper_queue.put(output) # Set last message variables self.last_colour = colour diff --git a/node-daemon/pvcnoded/Daemon.py b/node-daemon/pvcnoded/Daemon.py index 7c48b6d4..9fb4f338 100644 --- a/node-daemon/pvcnoded/Daemon.py +++ b/node-daemon/pvcnoded/Daemon.py @@ -63,7 +63,8 @@ def entrypoint(): # Get our configuration config = pvcnoded.util.config.get_configuration() - config["pvcnoded_version"] = version + config["daemon_name"] = "pvcnoded" + config["daemon_version"] = version # Create and validate our directories pvcnoded.util.config.validate_directories(config) diff --git a/node-daemon/pvcnoded/util/zookeeper.py b/node-daemon/pvcnoded/util/zookeeper.py index ed96f0ed..c4b7d447 100644 --- a/node-daemon/pvcnoded/util/zookeeper.py +++ b/node-daemon/pvcnoded/util/zookeeper.py @@ -123,7 +123,7 @@ def setup_node(logger, config, zkhandler): ), ( ("node.data.pvc_version", config["node_hostname"]), - config["pvcnoded_version"], + config["daemon_version"], ), ( ("node.ipmi.hostname", config["node_hostname"]), @@ -159,7 +159,7 @@ def setup_node(logger, config, zkhandler): ), ( ("node.data.pvc_version", config["node_hostname"]), - config["pvcnoded_version"], + config["daemon_version"], ), ( ("node.ipmi.hostname", config["node_hostname"]),