Skip to content

Commit

Permalink
Add ability to control minimum log priority, set default to NOTICE
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque committed Jul 22, 2020
1 parent 40a450b commit d65f683
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sonic-py-common/sonic_py_common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
FACILITY_USER = syslog.LOG_USER
FACILITY_DAEMON = syslog.LOG_DAEMON

PRIORITY_ERROR = syslog.LOG_ERR
PRIORITY_WARNING = syslog.LOG_WARNING
PRIORITY_NOTICE = syslog.LOG_NOTICE
PRIORITY_INFO = syslog.LOG_INFO
PRIORITY_DEBUG = syslog.LOG_DEBUG


class Logger(object):
"""
Logger class for SONiC Python applications
Expand All @@ -22,9 +29,15 @@ def __init__(self, log_identifier=None, log_facility=FACILITY_USER):
logoption=(syslog.LOG_PID | syslog.LOG_NDELAY),
facility=log_facility)

# Set the default minimum log priority to PRIORITY_NOTICE
self.set_min_log_priority(PRIORITY_NOTICE)

def __del__(self):
self.syslog.closelog()

def set_min_log_priority(priority):
self.syslog.setlogmask(self.syslog.LOG_UPTO(priority))

def log_error(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_ERR, msg)

Expand Down

0 comments on commit d65f683

Please sign in to comment.