You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use module-level named loggers instead of the root logger #48
24 log calls across 6 modules go to the root logger via the module-level functions — logging.warning(...), logging.error(...) — rather than a named logger:
Only csapi4py/mqtt.py:12 and csapi4py/nats.py:55 do the right thing with logger = logging.getLogger(__name__).
Two consequences for anything embedding OSHConnect:
No selective control. An app cannot raise OSHConnect to DEBUG, or silence its schema-fetch warnings, without reconfiguring the root logger and affecting every other library it uses.
Implicit basicConfig. Calling logging.warning(...) on the root logger auto-installs a handler on stderr if none exists — a library writing to a consumer's stderr uninvited.
Reproduce
importlogginglogging.getLogger("oshconnect").setLevel(logging.ERROR) # has no effectsystem.discover_datastreams() # schema-fetch warnings still print
(Note: the SchemaFetchWarning docstring in resources/base.py:56-58 names Node.discover_systems as a source of schema-fetch failures. It isn't — that
method never fetches a schema. Worth correcting while in here.)
Possible fix
Mechanical, one line per module plus a call-site rename:
logger=logging.getLogger(__name__)
...
logger.warning(...) # was logging.warning(...)
Add a NullHandler on the package logger in oshconnect/__init__.py so the library never configures logging for its consumer:
Then document the oshconnect.* logger namespace in the docs so consumers know what to configure.
Note resources/base.py and resources/system.py pair several of these log calls with warnings.warn(..., SchemaFetchWarning) — that dual-channel behavior is intentional (see the SchemaFetchWarning docstring) and should be preserved, not collapsed.
Activity