Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 10 additions & 39 deletions fwutil/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,22 @@
#

try:
import syslog
import click
from sonic_py_common import logger
except ImportError as e:
raise ImportError("Required module not found: {}".format(str(e)))

# ========================= Constants ==========================================

SYSLOG_IDENTIFIER = "fwutil"

# ========================= Helper classes =====================================

class SyslogLogger(object):
"""
SyslogLogger
"""
def __init__(self, identifier):
self.__syslog = syslog

self.__syslog.openlog(
ident=identifier,
logoption=self.__syslog.LOG_NDELAY,
facility=self.__syslog.LOG_USER
)

def __del__(self):
self.__syslog.closelog()
# ========================= Variables ==========================================

def log_error(self, msg):
self.__syslog.syslog(self.__syslog.LOG_ERR, msg)

def log_warning(self, msg):
self.__syslog.syslog(self.__syslog.LOG_WARNING, msg)

def log_notice(self, msg):
self.__syslog.syslog(self.__syslog.LOG_NOTICE, msg)

def log_info(self, msg):
self.__syslog.syslog(self.__syslog.LOG_INFO, msg)

def log_debug(self, msg):
self.__syslog.syslog(self.__syslog.LOG_DEBUG, msg)


logger = SyslogLogger(SYSLOG_IDENTIFIER)
# Global logger instance
log = logger.Logger(SYSLOG_IDENTIFIER)
log.set_min_log_priority_info()

# ========================= Helper classes =====================================

class LogHelper(object):
"""
Expand All @@ -67,7 +38,7 @@ def __log_fw_action_start(self, action, component, firmware):
caption = "Firmware {} started".format(action)
template = "{}: component={}, firmware={}"

logger.log_info(
log.log_info(
template.format(
caption,
component,
Expand All @@ -82,7 +53,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
exception_template = "{}: component={}, firmware={}, status={}, exception={}"

if status:
logger.log_info(
log.log_info(
status_template.format(
caption,
component,
Expand All @@ -92,7 +63,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
)
else:
if exception is None:
logger.log_error(
log.log_error(
status_template.format(
caption,
component,
Expand All @@ -101,7 +72,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
)
)
else:
logger.log_error(
log.log_error(
exception_template.format(
caption,
component,
Expand Down