Skip to content

Conversation

@nate-nexthop
Copy link

@nate-nexthop nate-nexthop commented Nov 12, 2025

Description

Fix logging in c_cmis.py to match neighboring files and to stop hijacking the syslog tag of any importing executables.

Motivation and Context

In python services using sonic_py_common.logger the syslog identifier already set up by the executable/service can be overwritten when importing other modules.

This log hijack is coming from a library: sonic_platform_base/sonic_xcvr/api/public/c_cmis.py

SYSLOG_IDENTIFIER = "CCmisApi"
...
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)
# This is the only log that this file has:
    helper_logger.log_debug('key {} not present in VDM'.format(new_key))

Searching in the syslog of a switch running SONiC we see logs with the CCmisApi that shouldn't:

2025-11-11T13:20:03.440479+00:00 sonic CCmisApi: Failed to load platform Pcie module. Warning : No module named 'sonic_platform.pcie', fallback to load Pcie common utility.
2025 Nov 11 13:20:45.179454 gold228 NOTICE CCmisApi: System is ready

If any code imports c_cmis.py (indirectly for the most part) and has a logger session open already, their existing session will be re-opened with a new log tag, CCmisApi which is not desired.

To fix this we remove this logging code entirely because the function where it is used became dead in #556

Libraries (rather than executables) probably shouldn't be syslogging on their own, and they certainly shouldn't hijack the log tag of the including executable.

Resolves sonic-net/sonic-buildimage#24489

How Has This Been Tested?

Before the fix:
Open an interactive python session and run this code:

from sonic_py_common import logger
log = logger.Logger("NATE")
log.log_notice("Log 1")
import sonic_platform
log.log_notice("Log 2")

Watch the syslog output:

2025 Nov 11 13:47:29.002667 gold228-dut NOTICE NATE: Log 1
2025 Nov 11 13:48:28.406481 gold228-dut NOTICE CCmisApi: Log 2

Clearly the second log should also have had the tag NATE

After the fix:
Syslog entries should have been:

2025 Nov 11 13:47:29.002667 gold228-dut NOTICE NATE: Log 1
2025 Nov 11 13:48:28.406481 gold228-dut NOTICE NATE: Log 2

Additional Information (Optional)

If any code imports c_cmis.py (indirectly for the most part) and has a
logger session open already, their existing session will be re-opened
with a new log tag, CCmisApi which is not desired.

To fix this we match the logging in c_cmis.py with logging in
neighboring files, it doesn't do any syslogging anymore.

Libraries (rather than executables) probably shouldn't be syslogging on
their own, and they certainly shouldn't hijack the log tag of the
including executable.
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@nate-nexthop
Copy link
Author

@prgeor and @mihirpat1 would you mind taking a look please?

@mihirpat1 mihirpat1 requested a review from Copilot November 13, 2025 23:57
Copilot finished reviewing on behalf of mihirpat1 November 13, 2025 23:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a logging issue where the c_cmis.py library file hijacks the syslog identifier of any importing executable by removing unused logging code and dead functions.

Key Changes:

  • Removed unused logger import and logging infrastructure that was overriding syslog identifiers
  • Removed dead code (_update_dict_if_vdm_key_exists method) that became unused in a previous PR
  • Removed unused BYTELENGTH constant

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: syslog identifier is hijacked to "CCmisApi" when importing sonic_platform

3 participants