From a9763c96929b331fb2bbe79b614d78a496098dea Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 16 May 2024 02:40:30 +0200 Subject: [PATCH] Initialize log config earlier to prevent trace messages being printed early on (#1939) like TRC DNS configuration loaded dns_config={....} --- cmd/headscale/cli/root.go | 2 -- hscontrol/types/config.go | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index 72c72a20..b0d9500e 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -56,8 +56,6 @@ func initConfig() { machineOutput := HasMachineOutputFlag() - zerolog.SetGlobalLevel(cfg.Log.Level) - // If the user has requested a "node" readable format, // then disable login so the output remains valid. if machineOutput { diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index fa3a64c6..bd0bfeac 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -640,6 +640,9 @@ func GetHeadscaleConfig() (*Config, error) { }, nil } + logConfig := GetLogConfig() + zerolog.SetGlobalLevel(logConfig.Level) + prefix4, err := PrefixV4() if err != nil { return nil, err @@ -667,7 +670,7 @@ func GetHeadscaleConfig() (*Config, error) { dnsConfig, baseDomain := GetDNSConfig() derpConfig := GetDERPConfig() - logConfig := GetLogTailConfig() + logTailConfig := GetLogTailConfig() randomizeClientPort := viper.GetBool("randomize_client_port") oidcClientSecret := viper.GetString("oidc.client_secret") @@ -749,7 +752,7 @@ func GetHeadscaleConfig() (*Config, error) { UseExpiryFromToken: viper.GetBool("oidc.use_expiry_from_token"), }, - LogTail: logConfig, + LogTail: logTailConfig, RandomizeClientPort: randomizeClientPort, ACL: GetACLConfig(), @@ -761,7 +764,7 @@ func GetHeadscaleConfig() (*Config, error) { Insecure: viper.GetBool("cli.insecure"), }, - Log: GetLogConfig(), + Log: logConfig, // TODO(kradalby): Document these settings when more stable Tuning: Tuning{