fix: route component log files added after profile routing is already on

Adoption of a second home only wrapped the file handlers that existed at
adoption time. A later setup_logging(hermes_home=<known>, mode="gateway")
skipped _adopt_secondary_home (the home is already served) and appended a
bare _ManagedRotatingFileHandler for gateway.log, which carries no home
filter and so took every profile's gateway records. When a router is
already queued, the new handler is now wrapped in a _ProfileRoutingFileHandler
over the union of the live routers' homes.

Review finding: setup_logging(A); setup_logging(B); setup_logging(A, mode="gateway") wrote gw-b into A's gateway.log.
This commit is contained in:
teknium1
2026-09-14 21:18:07 -07:00
committed by Teknium
parent c7a942e833
commit f8eb2912ce
2 changed files with 35 additions and 0 deletions
+11
View File
@@ -669,6 +669,17 @@ def _add_rotating_handler(
)
if log_filter is not None:
handler.addFilter(log_filter)
# Routing already on (a second home adopted earlier): a component log added now —
# ``mode="gateway"`` after the fact — must route too, or it takes every home's records.
routers = [h for h in _queued_file_handlers if isinstance(h, _ProfileRoutingFileHandler)]
if routers:
homes: set[Path] = set()
for router in routers:
homes.add(router._default_home)
homes.update(router._profile_homes)
routed = _ProfileRoutingFileHandler(handler, sorted(homes))
_quietly(handler.close)
handler = routed
# Queue, not ``addHandler``: the rotation-lock wait never runs on the caller's thread.
_register_queued_handler(handler)