aboutsummaryrefslogtreecommitdiffstats
path: root/snmptrap/mod/trapd_io.py
diff options
context:
space:
mode:
authorHansen, Tony (th1395) <th1395@att.com>2021-10-27 00:32:01 +0000
committerHansen, Tony (th1395) <th1395@att.com>2021-11-02 00:30:01 +0000
commit2861c7f08cba6c0cbd5af39aece1ab6c8bc3e368 (patch)
tree1beb52e5587af7ed165ebc88e22eab99d755b9d0 /snmptrap/mod/trapd_io.py
parent7d0c9432f13d83ed19cc07d3a61cc528b3942822 (diff)
send stdout logging to stdout in addition to log files
Change-Id: Icad02afe29e28eef72cc36dd82f0a64810ce9500 Signed-off-by: Hansen, Tony (th1395) <th1395@att.com> Issue-ID: DCAEGEN2-2957 Signed-off-by: Hansen, Tony (th1395) <th1395@att.com>
Diffstat (limited to 'snmptrap/mod/trapd_io.py')
-rw-r--r--snmptrap/mod/trapd_io.py13
1 files changed, 13 insertions, 0 deletions
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))