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

From 5a7a5bc2ea32e9e1be244c64dcf362726c81d824 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20Gr=C3=B6nlund?= <krig@koru.se>
Date: Wed, 16 May 2018 08:48:59 +0200
Subject: [PATCH] fencing: include timestamps when logging to STDERR and debug
 file (bsc#1049852)

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 0e57e39a..6ba174b7 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -34,6 +34,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",
@@ -644,10 +646,14 @@ def check_input(device_opt, opt, other_conditions = False):
 	if options.has_key("--verbose"):
 		logging.getLogger().setLevel(logging.DEBUG)
 
+	formatter = logging.Formatter(LOG_FORMAT)
+
 	## add logging to syslog
 	logging.getLogger().addHandler(SyslogLibHandler())
 	## add logging to stderr
-	logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stderr))
+	stderrHandler = logging.StreamHandler(sys.stderr)
+	stderrHandler.setFormatter(formatter)
+	logging.getLogger().addHandler(stderrHandler)
 
 	(acceptable_actions, _) = _get_available_actions(device_opt)
 
@@ -675,6 +681,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.16.3

openSUSE Build Service is sponsored by