Add diagnostics / logging package with full logger coverage#163
Merged
rhurey merged 6 commits intoMar 4, 2026
Merged
Conversation
Add new diagnostics/logging sub-package providing idiomatic Go APIs for Speech SDK diagnostics, matching feature parity with Java/Python/C# bindings: - FileLogger: file-based logging with append mode, filters, levels - MemoryLogger: ring-buffer logging with Dump/DumpToWriter/DumpToSlice/DumpToStderr/DumpOnExit - EventLogger: callback-based log streaming with mutex-guarded dispatch - ConsoleLogger: stdout/stderr logging with filters and levels - Trace helpers: TraceError/Warning/Info/Verbose with auto and explicit caller info - Level type: Error(0x02), Warning(0x04), Info(0x08), Verbose(0x10) Updated diagnostics package: - Added StartFileLogging/StopFileLogging via property_bag API - Updated StartConsoleLogging to accept variadic bool - Added Deprecated markers pointing users to diagnostics/logging - Enhanced error.go with native error message lookup Tests (49 total): - diagnostics_test.go: 3 legacy API tests - logging/logging_test.go: 46 tests covering all loggers, trace helpers, input validation, error paths, idempotent operations, and content verification - All tests pass with race detector enabled
Keep all diagnostics documentation in diagnostics/README.md to scope the PR to the diagnostics directory.
…prune subset tests
rhurey
reviewed
Feb 26, 2026
rhurey
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Go Diagnostics Binding Architecture
This document describes the architecture used for the Go Diagnostics API in Speech SDK bindings.
Goals
diagnosticspackage.Package Layout
diagnostics/logging(new primary API)This package contains the full diagnostics surface:
FileLoggerfor file loggingMemoryLoggerfor memory-ring logging and dump helpersEventLoggerfor callback-based log streamingConsoleLoggerfor stdout/stderr loggingTraceError,TraceWarning,TraceInfo,TraceVerbose(+WithCallervariants)Levelenum-like type (Error,Warning,Info,Verbose)Files are intentionally split by logger/type to keep ownership and review scope small.
diagnostics(deprecated compatibility layer)This package keeps old entry points available and forwards behavior to equivalent native diagnostics APIs.
Deprecated:comments.diagnostics/logging.Architectural Decisions
1) Singleton logger model
Each logger is a package-level singleton (
FileLogger,MemoryLogger, etc.) matching the native SDK's process-wide semantics and the shape used in other language bindings.2) Thin wrappers around native C APIs
Go methods map ~1:1 to native diagnostics APIs from
speechapi_c_diagnostics.h, keeping behavior changes centralized in the native layer.3) Explicit CGo boundary ownership
All callback bridge code lives in
logging/cfunctions.go: C trampoline -> exported Go function -> mutex-guarded dispatch. This avoids glue duplication and keeps thread-safety constraints visible.4) Property bag for file logger configuration
FileLogger.StartpassesSPEECH-LogFilenameandSPEECH-AppendToLogFilevia a temporary property bag, mirroring the native/C++/Java pattern.5) Backward compatibility strategy
Legacy
diagnosticspackage stays available withDeprecated:markers guiding users todiagnostics/logging.Error Handling
SPXHR/AZACHR) surface as Goerrorvalues via lightweight wrappers.voidAPIs remain fire-and-forget. Invalid caller input is validated early where useful.Concurrency
EventLoggerprotects state with a mutex; callback handlers should be fast and non-blocking.Testing
49 tests total (3 in
diagnostics_test.go, 46 inlogging/logging_test.go).Integration tests are gated by
SPEECH_SDK_AVAILABLE=1; pure unit tests (e.g.TestLevelString,TestLoggingError) run unconditionally.File Inventory
logging/doc.gologging/level.gologging/error.gologging/cfunctions.gologging/file_logger.gologging/memory_logger.gologging/event_logger.gologging/console_logger.gologging/spx_trace.gologging/logging_test.godiagnostics.godiagnostics_test.goerror.goLocal Validation
Requirements: Go toolchain, CGo-compatible C compiler, Speech SDK headers and native library.
Key environment variables:
CGO_ENABLED=1,CGO_CFLAGS(header path),CGO_LDFLAGS(lib path),SPEECH_SDK_AVAILABLE=1.Run tests via CMake:
Extension Guidelines
diagnostics/loggingfirst.diagnosticswhen needed for non-breaking upgrades.Known Constraints
SPEECH_SDK_AVAILABLE=1.