Skip to content

fix: gate networkmock logging #86

Description

@MaxMichel2

Summary

devview-networkmock-core and devview-networkmock-ktor emit roughly 65 unconditional println calls covering every step of config loading, request matching, and response serving. These ship straight into any host app's logcat, unconditionally, with no way to turn them off — and several of them log full request URLs and response bodies. This is independent of the OpenAPI migration (tracked in the epic, #72) and can be picked up any time.

Current state

Two hot spots:

  • MockConfigRepositorydevview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockConfigRepository.kt, roughly 25 println calls across loadConfiguration() (:206-252) and findMatchingMock() (:292-377), including per-group and per-environment iteration logging and full path/method/query comparison traces on every single intercepted request.
  • NetworkMockPlugindevview-networkmock-ktor/src/commonMain/kotlin/com/worldline/devview/networkmock/ktor/plugin/NetworkMockPlugin.kt, roughly 40 println calls (LOG_PREFIX constant at :37) covering plugin install, every intercepted request's host/path/method (:170), full mock-vs-network decision tracing, and — notably — the response file name and status code on every successful mock (:248-249).
  • MockStateRepository also logs on every state write (setGlobalMockingEnabled :240,245, setEndpointMockState :271-273, setAllEndpointStates :334-336, all in devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockStateRepository.kt).

None of this is gated behind a log level, a debug flag, or a way to disable it. A host app integrating this library gets this in its logcat/console on every request, all the time, with no opt-out — and depending on mock content, response bodies could contain data a team doesn't want silently duplicated into device logs.

What to build

Introduce a minimal logging abstraction (or reuse one if this repo already has a shared logging convention elsewhere in DevView — check before adding a new one) with at least an on/off gate, defaulting to a sensible state for a developer tool (arguably on-by-default is fine for a dev-only overlay tool, but it must be possible to turn off, and it should not be the current firehose of ~40+ lines per single request).

Suggested minimal shape: a single NetworkMockLogger (or similar) with a enabled: Boolean toggle, injected the same way NetworkMockResourceLoader already is, replacing every println call site. Consider consolidating the current multi-line-per-request tracing into a single structured log line per request (e.g. one line: method path -> MOCK|NETWORK (reason)), which both reduces log volume and reduces sensitive-data exposure (drop full response bodies from logs entirely — the status code and file/example name is enough context).

Acceptance criteria

  • All ~65 println calls across devview-networkmock-core and devview-networkmock-ktor are replaced with a gated logging call.
  • Logging can be disabled entirely by a host app.
  • No response body content is ever logged (status code + example identifier is sufficient).
  • Existing tests that assert on println output (if any — check MockConfigRepositoryTest.kt, NetworkMockPluginTest.kt) are updated accordingly.

Files likely touched

  • devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockConfigRepository.kt
  • devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockStateRepository.kt
  • devview-networkmock-ktor/src/commonMain/kotlin/com/worldline/devview/networkmock/ktor/plugin/NetworkMockPlugin.kt
  • New shared logging utility, likely in devview-networkmock-core

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions