Skip to content

Commit

Permalink
route_check.py should not print too many outputs to stdout
Browse files Browse the repository at this point in the history
Otherwise it fills up the pipe and print() will block.
  • Loading branch information
MaxXiao12 committed Dec 7, 2023
1 parent 3037959 commit f5b8db7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def set_level(lvl, log_to_syslog):
report_level = syslog.LOG_DEBUG


def print_message(lvl, *args):
def print_message(lvl, *args, write_to_stdout=True):
"""
print and log the message for given level.
:param lvl: Log level for this message as ERR/INFO/DEBUG
:param args: message as list of strings or convertible to string
:param write_to_stdout: print the message to stdout if set to true
:return None
"""
msg = ""
Expand All @@ -129,7 +130,8 @@ def print_message(lvl, *args):
break
msg += str(arg)[0:rem_len]

print(msg)
if write_to_stdout:
print(msg)
if write_to_syslog:
syslog.syslog(lvl, msg)

Expand Down Expand Up @@ -575,7 +577,7 @@ def mitigate_installed_not_offloaded_frr_routes(missed_frr_rt, rt_appl):
fvs = swsscommon.FieldValuePairs([('err_str', 'SWSS_RC_SUCCESS'), ('protocol', entry['protocol'])])
response_producer.send('SWSS_RC_SUCCESS', entry['prefix'], fvs)

print_message(syslog.LOG_ERR, f'Mitigated route {entry["prefix"]}')
print_message(syslog.LOG_ERR, f'Mitigated route {entry["prefix"]}', write_to_stdout=False)


def get_soc_ips(config_db):
Expand Down

0 comments on commit f5b8db7

Please sign in to comment.