[action] [PR:609] Fix log prefix hijack in c_cmis.py#630
Merged
mssonicbld merged 1 commit intosonic-net:202511from Mar 9, 2026
Merged
[action] [PR:609] Fix log prefix hijack in c_cmis.py#630mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld merged 1 commit intosonic-net:202511from
Conversation
<!-- Provide a general summary of your changes in the Title above -->
#### Description
<!--
Describe your changes in detail
-->
Remove calls to setting a syslog tag as there was no logging actually used in this module. The existing call to log a message was in dead code, therefore there was no need to setup a syslogger at all.
#### Motivation and Context
<!--
Why is this change required? What problem does it solve?
If this pull request closes/resolves an open Issue, make sure you
include the text "fixes #xxxx", "closes #xxxx" or "resolves #xxxx" here
-->
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 sonic-net#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?
<!--
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.
-->
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
```
Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
#### Additional Information (Optional)
Collaborator
Author
|
Original PR: #609 |
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Remove calls to setting a syslog tag as there was no logging actually used in this module. The existing call to log a message was in dead code, therefore there was no need to setup a syslogger at all.
Motivation and Context
In python services using
sonic_py_common.loggerthe 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.pySearching in the syslog of a switch running SONiC we see logs with the
CCmisApithat shouldn't: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,
CCmisApiwhich 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:
Watch the syslog output:
Clearly the second log should also have had the tag
NATEAfter the fix:
Syslog entries should have been:
Signed-off-by: Sonic Build Admin sonicbld@microsoft.com
Additional Information (Optional)