Skip to content

Commit 29e4469

Browse files
authored
[201911][fwutil]: Use logger from sonic-py-common (sonic-net#1190)
Reduced code duplication: replaced logger with common implementation from sonic-py-common Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent ce0bebe commit 29e4469

File tree

1 file changed

+10
-39
lines changed

1 file changed

+10
-39
lines changed

fwutil/log.py

+10-39
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,22 @@
66
#
77

88
try:
9-
import syslog
109
import click
10+
from sonic_py_common import logger
1111
except ImportError as e:
1212
raise ImportError("Required module not found: {}".format(str(e)))
1313

1414
# ========================= Constants ==========================================
1515

1616
SYSLOG_IDENTIFIER = "fwutil"
1717

18-
# ========================= Helper classes =====================================
19-
20-
class SyslogLogger(object):
21-
"""
22-
SyslogLogger
23-
"""
24-
def __init__(self, identifier):
25-
self.__syslog = syslog
26-
27-
self.__syslog.openlog(
28-
ident=identifier,
29-
logoption=self.__syslog.LOG_NDELAY,
30-
facility=self.__syslog.LOG_USER
31-
)
32-
33-
def __del__(self):
34-
self.__syslog.closelog()
18+
# ========================= Variables ==========================================
3519

36-
def log_error(self, msg):
37-
self.__syslog.syslog(self.__syslog.LOG_ERR, msg)
38-
39-
def log_warning(self, msg):
40-
self.__syslog.syslog(self.__syslog.LOG_WARNING, msg)
41-
42-
def log_notice(self, msg):
43-
self.__syslog.syslog(self.__syslog.LOG_NOTICE, msg)
44-
45-
def log_info(self, msg):
46-
self.__syslog.syslog(self.__syslog.LOG_INFO, msg)
47-
48-
def log_debug(self, msg):
49-
self.__syslog.syslog(self.__syslog.LOG_DEBUG, msg)
50-
51-
52-
logger = SyslogLogger(SYSLOG_IDENTIFIER)
20+
# Global logger instance
21+
log = logger.Logger(SYSLOG_IDENTIFIER)
22+
log.set_min_log_priority_info()
5323

24+
# ========================= Helper classes =====================================
5425

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

70-
logger.log_info(
41+
log.log_info(
7142
template.format(
7243
caption,
7344
component,
@@ -82,7 +53,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
8253
exception_template = "{}: component={}, firmware={}, status={}, exception={}"
8354

8455
if status:
85-
logger.log_info(
56+
log.log_info(
8657
status_template.format(
8758
caption,
8859
component,
@@ -92,7 +63,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
9263
)
9364
else:
9465
if exception is None:
95-
logger.log_error(
66+
log.log_error(
9667
status_template.format(
9768
caption,
9869
component,
@@ -101,7 +72,7 @@ def __log_fw_action_end(self, action, component, firmware, status, exception=Non
10172
)
10273
)
10374
else:
104-
logger.log_error(
75+
log.log_error(
10576
exception_template.format(
10677
caption,
10778
component,

0 commit comments

Comments
 (0)