Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xcvrd] enable setting log level at real time #422

Closed
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#from unittest.mock import DEFAULT
import os
os.environ["XCVRD_UNIT_TESTING"] = "1"
from xcvrd.xcvrd_utilities.port_mapping import *
from xcvrd.xcvrd_utilities.sfp_status_helper import *
from xcvrd.xcvrd_utilities.media_settings_parser import *
Expand Down Expand Up @@ -34,8 +36,6 @@
sys.path.insert(0, modules_path)
DEFAULT_NAMESPACE = ['']

os.environ["XCVRD_UNIT_TESTING"] = "1"

with open(os.path.join(test_path, 'media_settings.json'), 'r') as f:
media_settings_dict = json.load(f)

Expand Down
6 changes: 1 addition & 5 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .xcvrd_utilities import port_mapping
from .xcvrd_utilities import media_settings_parser
from .xcvrd_utilities import optics_si_parser
from .xcvrd_utilities.logger import logger as helper_logger

from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CmisApi

Expand Down Expand Up @@ -98,11 +99,6 @@
# Global chassis object based on new platform api
platform_chassis = None

# Global logger instance for helper functions and classes
# TODO: Refactor so that we only need the logger inherited
# by DaemonXcvrd
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)

#
# Helper functions =============================================================
#
Expand Down
12 changes: 12 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from sonic_py_common.logger import Logger

# Global logger instance for xcvrd, the argument "enable_set_log_level_on_fly"
# will start a thread to detect CONFIG DB LOGGER table change. The logger instance
# allow user to set log level via swssloglevel command at real time. This instance
# should be shared by all modules of xcvrd to avoid starting too many logger thread.
if os.environ.get("XCVRD_UNIT_TESTING") != "1":
logger = Logger(log_identifier='xcvrd', enable_set_log_level_on_fly=True)
else:
# for unit test, there is no redis, don't set enable_set_log_level_on_fly=True
logger = Logger(log_identifier='xcvrd')
5 changes: 2 additions & 3 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import os
import ast

from sonic_py_common import device_info, logger
from sonic_py_common import device_info
from swsscommon import swsscommon
from xcvrd import xcvrd
from .logger import logger as helper_logger

g_dict = {}

LANE_SPEED_KEY_PREFIX = "speed:"
VENDOR_KEY = 'vendor_key'
MEDIA_KEY = 'media_key'
LANE_SPEED_KEY = 'lane_speed_key'
SYSLOG_IDENTIFIER = "xcvrd"
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)


def load_media_settings():
Expand Down
5 changes: 2 additions & 3 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import os

from sonic_py_common import device_info, logger
from sonic_py_common import device_info
from xcvrd import xcvrd
from .logger import logger as helper_logger

g_optics_si_dict = {}

SYSLOG_IDENTIFIER = "xcvrd"
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)

def get_optics_si_settings_value(physical_port, lane_speed, key, vendor_name_str):
GLOBAL_MEDIA_SETTINGS_KEY = 'GLOBAL_MEDIA_SETTINGS'
Expand Down