From ba9a42b64efe6bae4df15828cf2237d3d496f73e Mon Sep 17 00:00:00 2001 From: Darell Tan Date: Fri, 4 Aug 2023 00:56:30 +0800 Subject: [PATCH] Added quiet mode for reduced verbosity This is useful to reduce clutter if you're running the service and it's writing logs to the main syslog. --- bridge.go | 3 ++- cmd/hapz2m/main.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bridge.go b/bridge.go index 24bd257..fd54d85 100644 --- a/bridge.go +++ b/bridge.go @@ -56,6 +56,7 @@ type Bridge struct { Interfaces []string DebugMode bool + QuietMode bool ctx context.Context bridgeAcc *accessory.Bridge @@ -561,7 +562,7 @@ func (br *Bridge) UpdateAccessoryState(devName string, payload []byte) { return } - if br.DebugMode || time.Since(dev.LastSeen) > 30*time.Second { + if br.DebugMode || (!br.QuietMode && time.Since(dev.LastSeen) > 30*time.Second) { log.Printf("received update for device %q", devName) } diff --git a/cmd/hapz2m/main.go b/cmd/hapz2m/main.go index a3f3b2b..7b2cacb 100644 --- a/cmd/hapz2m/main.go +++ b/cmd/hapz2m/main.go @@ -28,6 +28,7 @@ var ( configFile = flag.String("config", "/etc/hapz2m.conf", "config file") dbPath = flag.String("db", "/var/lib/hapz2m", "db path") debugMode = flag.Bool("debug", false, "enable debug messages") + quietMode = flag.Bool("quiet", false, "reduce verbosity by not showing received upates") ) // config struct @@ -77,6 +78,11 @@ func main() { br.Username = cfg.Username br.Password = cfg.Password br.DebugMode = *debugMode + br.QuietMode = *quietMode + + if *debugMode && *quietMode { + log.Fatalf("-quiet and -debug options are mutually-exclusive") + } // validate ListenAddr if specified if cfg.ListenAddr != "" {