Skip to content

Fixing logging used by sonic_platform_base classes to prevent log pollution - #761

Open
gordon-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:fix_base_class_log_override
Open

gordon-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:fix_base_class_log_override

Conversation

@gordon-nexthop

@gordon-nexthop gordon-nexthop commented Sep 17, 2026

Copy link
Copy Markdown

Description

Convert the module-level loggers in sonic_platform_base from
sonic_py_common.logger.Logger to sonic_py_common.syslogger.SysLogger:
bmc_base.py, redfish_client.py, sed_mgmt_base.py and bmc_fw_update.py.

Logger is a thin wrapper around the C syslog API, and its constructor calls
syslog.openlog(), which sets one identifier for the whole process. These modules
build a Logger at import time, so simply importing them renames every subsequent syslog
message emitted anywhere in the importing process.

SysLogger instead attaches a SysLogHandler to a named logging.Logger, so the identifier
belongs to the logger instance rather than to the process. Importing a module can no longer
change how unrelated code in the same process is tagged, and each module still logs under its
own name. This is already the pattern used by sonic_platform_base/sonic_xcvr/cdb/.

Motivation and Context

fixes: #760

How Has This Been Tested?

On hardware. Nexthop 4010 (x86_64-nexthop_4010-r0, HwSKU NH-4010, SONiC master,
Python 3.13) — deliberately a non-BMC platform, since the bug reaches those too.

  1. ZTP import chain. A probe that mirrors what ztp-engine.py does — construct
    Logger('sonic-ztp'), log, import sonic_platform.platform, log again — with
    syslog.openlog wrapped to record every identifier it is called with:

    openlog() idents, in order effective process ident
    before ['sonic-ztp', 'redfish_client', 'bmc_base'] bmc_base
    after ['sonic-ztp'] sonic-ztp

    and the resulting /var/log/syslog lines:

    # before
    NOTICE sonic-ztp:  probe before-import: ZTP service started.
    NOTICE bmc_base:   probe after-import: ZTP service still running.
    # after
    NOTICE sonic-ztp:  probe before-import: ZTP service started.
    NOTICE sonic-ztp:  probe after-import: ZTP service still running.
    
  2. The real ztp service. systemctl start ztp (ZTP admin mode disabled, so it just bails)
    now logs under its own identifier, and no bmc_base-tagged line was emitted by anything on
    the switch after the swap:

    INFO sonic-ztp[768842]: ZTP is administratively disabled.
    
  3. No regression to BMC logging. Importing the modules and logging through them directly
    still produces their own identifiers — now with the PID, since SysLogger formats as
    %(name)s[%(process)d] — and RedfishClient still constructs:

    NOTICE redfish_client[768154]: ...
    NOTICE bmc_base[768154]: ...
    NOTICE sed_mgmt_base[768154]: ...
    
  4. Platform API smoke test. show platform summary, show platform psustatus and
    docker exec pmon supervisorctl status were all healthy with the patched modules in place
    (pcied, psud, sensormond, stormond, syseepromd, thermalctld, xcvrd all RUNNING).

Additional Information (Optional)

Signed-off-by: gordon-nexthop <gordon@nexthop.ai>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@gordon-nexthop gordon-nexthop changed the title Fixing logging used by bmc base classes to prevent log pollution Fixing logging used by sonic_platform_base classes to prevent log pollution Sep 17, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@gordon-nexthop
gordon-nexthop marked this pull request as ready for review September 17, 2026 22:26
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@gordon-nexthop

Copy link
Copy Markdown
Author

@benle7 would you mind taking a peak at this one!

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

nh-grecs Bot pushed a commit to nexthop-ai/sonic-platform-common that referenced this pull request Sep 19, 2026
…lution

rebuild-source: sonic-net#761 @ nexthop-ai/sonic-platform-common 8957705 [case: upstream:open]
nh-grecs Bot pushed a commit to nexthop-ai/sonic-platform-common that referenced this pull request Sep 19, 2026
…lution

rebuild-source: sonic-net/pull/761 @ nexthop-ai/sonic-platform-common 8957705 [case: upstream:open]
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.

[sonic_platform_base] Module level loggers overwriting log identifiers for processes that import sonic_platform

2 participants