Skip to content

[action] [PR:609] Fix log prefix hijack in c_cmis.py#630

Merged
mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/609
Mar 9, 2026
Merged

[action] [PR:609] Fix log prefix hijack in c_cmis.py#630
mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/609

Conversation

@mssonicbld
Copy link
Copy Markdown
Collaborator

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.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

Signed-off-by: Sonic Build Admin sonicbld@microsoft.com

Additional Information (Optional)

<!-- 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)
@mssonicbld
Copy link
Copy Markdown
Collaborator Author

Original PR: #609

@mssonicbld
Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld merged commit 8a3bf99 into sonic-net:202511 Mar 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant