feat: turn on gosnmp logging in debug mode #213
Merged
+48
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors the SNMP client factory and related code to allow passing a logger for improved logging and debugging. It introduces a new
SlogAdapterto integrate structured logging with the underlying SNMP library, and updates all usages and tests to support the new logger-aware client factory signature.Logging integration and client factory refactor
ClientFactorytype and all usages to accept a*slog.Loggerparameter, enabling logger-aware SNMP client creation throughout the codebase. (snmp-discovery/snmp/snmp.go,snmp-discovery/policy/manager.go,snmp-discovery/snmp/mocks.go,snmp-discovery/snmp/snmp_test.go) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]SlogAdaptertype to bridgeslog.Loggerwith thegosnmp.LoggerInterface, ensuring SNMP debug output is captured in structured logs when debug is enabled. (snmp-discovery/snmp/snmp.go)NewClientfunction to attach agosnmp.Loggerwhen debug logging is enabled, and propagate the logger to SNMP client instances for all supported protocol versions. (snmp-discovery/snmp/snmp.go) [1] [2] [3] [4]Test and mock updates
snmp-discovery/snmp/snmp_test.go,snmp-discovery/snmp/mocks.go,snmp-discovery/policy/runner_test.go) [1] [2] [3] [4] [5] [6] [7] [8] [9]Minor improvements
time,log/slog,context) to support new functionality. (snmp-discovery/policy/manager.go,snmp-discovery/snmp/mocks.go,snmp-discovery/snmp/snmp.go) [1] [2] [3]This refactor improves observability and debugging for SNMP operations, making it easier to trace issues and monitor SNMP interactions in production environments.
Example output