mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-24 14:47:23 +00:00
Discovery cycles emit one line per UPnP M-SEARCH header, one per
parsed response, and one per enrichment step — by default. A typical
service-binary cycle prints ~50–80 lines for a 3-speaker LAN. Most
operators want a startup-and-summary view; the per-packet trace is
only useful for debugging.
- New SetVerbose/IsVerbose/logVerbose helpers in pkg/discovery (atomic
bool, zero-value off).
- Chatty log.Printf calls in upnp.go and mdns.go demoted to logVerbose:
per-header dumps, per-response dumps, per-device enrichment steps,
M-SEARCH details, read-deadline / cancel-context noise.
- Kept at default level: discovery start ("Starting SSDP discovery
for…"), end ("Discovery completed. Processed N responses, found N
unique devices" + per-device summary), warnings ("Configured
interface not found", "Failed to fetch device description", …), and
the new "Rejecting non-Bose device" classifier.
- cmd/soundtouch-cli/discover devices grew a --verbose / -v flag that
flips the package toggle on; the service binary leaves it at the
zero value.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package discovery
|
|
|
|
import (
|
|
"log"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// verboseLogging toggles the per-packet / per-header diagnostic output
|
|
// that was historically emitted unconditionally during UPnP and mDNS
|
|
// discovery. The service binary leaves it at its zero value (off) so
|
|
// the log stays useful at info-level; the CLI's `discover` command
|
|
// flips it on so interactive runs surface full protocol details.
|
|
//
|
|
// Stored as an int32 so the read path in logVerbose is allocation-
|
|
// free (atomic.Bool would work too on Go 1.19+, but a uint8 lookup
|
|
// keeps the toggle hot-path even on older toolchains we still build
|
|
// against in CI).
|
|
var verboseLogging atomic.Bool
|
|
|
|
// SetVerbose enables (or disables) the package-wide verbose-discovery
|
|
// log toggle. Safe to call from any goroutine.
|
|
func SetVerbose(v bool) {
|
|
verboseLogging.Store(v)
|
|
}
|
|
|
|
// IsVerbose reports the current value of the verbose toggle. Mainly
|
|
// for tests that want to assert the CLI flipped it on.
|
|
func IsVerbose() bool {
|
|
return verboseLogging.Load()
|
|
}
|
|
|
|
// logVerbose forwards to log.Printf only when verbose-discovery
|
|
// logging is enabled. The fast path (verbose off) is a single
|
|
// atomic load + branch, so it's safe to scatter calls liberally
|
|
// across the hot path.
|
|
func logVerbose(format string, args ...any) {
|
|
if verboseLogging.Load() {
|
|
log.Printf(format, args...)
|
|
}
|
|
}
|