Skip to content

Commit

Permalink
fix the issue "'NoneType' object has no attribute 'closelog'" which r…
Browse files Browse the repository at this point in the history
…esults from referencing an already destroyed global variable when destructuring daemon_base.Logger by introducing a class member to represent the global (#3281)
  • Loading branch information
stephenxs authored and jleveque committed Aug 5, 2019
1 parent 1dd2688 commit 530a0c9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/sonic-daemon-base/sonic_daemon_base/daemon_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,38 @@ def db_connect(db):

class Logger(object):
def __init__(self, syslog_identifier):
syslog.openlog(ident=syslog_identifier, logoption=syslog.LOG_NDELAY, facility=syslog.LOG_DAEMON)
self.syslog = syslog
self.syslog.openlog(ident=syslog_identifier, logoption=self.syslog.LOG_NDELAY, facility=self.syslog.LOG_DAEMON)

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

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

if also_print_to_console:
print msg

def log_warning(self, msg, also_print_to_console=False):
syslog.syslog(syslog.LOG_WARNING, msg)
self.syslog.syslog(self.syslog.LOG_WARNING, msg)

if also_print_to_console:
print msg

def log_notice(self, msg, also_print_to_console=False):
syslog.syslog(syslog.LOG_NOTICE, msg)
self.syslog.syslog(self.syslog.LOG_NOTICE, msg)

if also_print_to_console:
print msg

def log_info(self, msg, also_print_to_console=False):
syslog.syslog(syslog.LOG_INFO, msg)
self.syslog.syslog(self.syslog.LOG_INFO, msg)

if also_print_to_console:
print msg

def log_debug(self, msg, also_print_to_console=False):
syslog.syslog(syslog.LOG_DEBUG, msg)
self.syslog.syslog(self.syslog.LOG_DEBUG, msg)

if also_print_to_console:
print msg
Expand All @@ -98,15 +99,15 @@ def __init__(self):
# Signal handler
def signal_handler(self, sig, frame):
if sig == signal.SIGHUP:
syslog.syslog(syslog.LOG_INFO, "Caught SIGHUP - ignoring...")
self.syslog.syslog(self.syslog.LOG_INFO, "Caught SIGHUP - ignoring...")
elif sig == signal.SIGINT:
syslog.syslog(syslog.LOG_INFO, "Caught SIGINT - exiting...")
self.syslog.syslog(self.syslog.LOG_INFO, "Caught SIGINT - exiting...")
sys.exit(128 + sig)
elif sig == signal.SIGTERM:
syslog.syslog(syslog.LOG_INFO, "Caught SIGTERM - exiting...")
self.syslog.syslog(self.syslog.LOG_INFO, "Caught SIGTERM - exiting...")
sys.exit(128 + sig)
else:
syslog.syslog(syslog.LOG_WARNING, "Caught unhandled signal '" + sig + "'")
self.syslog.syslog(self.syslog.LOG_WARNING, "Caught unhandled signal '" + sig + "'")

# Returns platform and hwsku
def get_platform_and_hwsku(self):
Expand Down

0 comments on commit 530a0c9

Please sign in to comment.