File 0018-fencing-include-timestamps-when-logging-to-STDERR-an.patch of Package fence-agents.8763

From a1b3ce9f9343b2e660c77a85d29ea0dff1321e07 Mon Sep 17 00:00:00 2001
From: Adam Spiers <aspiers@suse.com>
Date: Tue, 17 Oct 2017 14:15:04 +0100
Subject: [PATCH] fencing: include timestamps when logging to STDERR and debug
 file

When logging to STDERR (i.e. when --quiet is not specified), or when
logging to a debug file via --debug-file, include timestamps so that
exact timings of fencing actions can be correlated with events logged
elsewhere.
---
 fence/agents/lib/fencing.py.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 7f4d8939..0471b870 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -28,6 +28,8 @@ EC_STATUS_HMC = 9
 EC_PASSWORD_MISSING = 10
 EC_INVALID_PRIVILEGES = 11
 
+LOG_FORMAT = "%(asctime)-15s %(levelname)s: %(message)s"
+
 all_opt = {
 	"help"    : {
 		"getopt" : "h",
@@ -677,11 +679,15 @@ def check_input(device_opt, opt, other_conditions = False):
 	if "--verbose" in options:
 		logging.getLogger().setLevel(logging.DEBUG)
 
+	formatter = logging.Formatter(LOG_FORMAT)
+
 	## add logging to syslog
 	logging.getLogger().addHandler(SyslogLibHandler())
 	if "--quiet" not in options:
 		## add logging to stderr
-		logging.getLogger().addHandler(logging.StreamHandler(sys.stderr))
+		stderrHandler = logging.StreamHandler(sys.stderr)
+		stderrHandler.setFormatter(formatter)
+		logging.getLogger().addHandler(stderrHandler)
 
 	(acceptable_actions, _) = _get_available_actions(device_opt)
 
@@ -710,6 +716,7 @@ def check_input(device_opt, opt, other_conditions = False):
 		try:
 			debug_file = logging.FileHandler(options["--debug-file"])
 			debug_file.setLevel(logging.DEBUG)
+			debug_file.setFormatter(formatter)
 			logging.getLogger().addHandler(debug_file)
 		except IOError:
 			logging.error("Unable to create file %s", options["--debug-file"])
-- 
2.13.6

openSUSE Build Service is sponsored by