From 2861c7f08cba6c0cbd5af39aece1ab6c8bc3e368 Mon Sep 17 00:00:00 2001 From: "Hansen, Tony (th1395)" Date: Wed, 27 Oct 2021 00:32:01 +0000 Subject: send stdout logging to stdout in addition to log files Change-Id: Icad02afe29e28eef72cc36dd82f0a64810ce9500 Signed-off-by: Hansen, Tony (th1395) Issue-ID: DCAEGEN2-2957 Signed-off-by: Hansen, Tony (th1395) --- snmptrap/mod/trapd_io.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'snmptrap/mod/trapd_io.py') diff --git a/snmptrap/mod/trapd_io.py b/snmptrap/mod/trapd_io.py index 991bcbd..20b99f9 100644 --- a/snmptrap/mod/trapd_io.py +++ b/snmptrap/mod/trapd_io.py @@ -303,6 +303,9 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): unused = "" + # new requirement to send all logs to stdout + log_to_stdout = True + # above were various attempts at setting time string found in other # libs; instead, let's keep it real: t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] @@ -319,6 +322,8 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, (msg + _msg))) try: tds.eelf_error_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + if log_to_stdout: + print('%s|%s' % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) @@ -334,6 +339,8 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): % (unused, unused, calling_fx, unused, "snmptrapd", unused, unused, unused, unused, unused, unused, unused, tds.SEV_TYPES[_sev], unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, _msg)) try: tds.eelf_error_fd.write('%s|%s|%s\n' % (t_out, t_out, str(_out_rec))) + if log_to_stdout: + print('%s|%s|%s' % (t_out, t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) elif _log_type == tds.LOG_TYPE_AUDIT: @@ -344,6 +351,8 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) try: tds.eelf_audit_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + if log_to_stdout: + print('%s|%s' % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) elif _log_type == tds.LOG_TYPE_METRICS: @@ -352,6 +361,8 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) try: tds.eelf_metrics_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + if log_to_stdout: + print('%s|%s' % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) @@ -363,6 +374,8 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): % (unused, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) try: tds.eelf_debug_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + if log_to_stdout: + print('%s|%s' % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) -- cgit 1.2.3-korg