mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-31 16:11:03 +01:00 
			
		
		
		
	toggle json logging via config
This commit is contained in:
		
							parent
							
								
									cc0bec15ef
								
							
						
					
					
						commit
						2403c0e198
					
				| @ -55,6 +55,10 @@ func initConfig() { | |||||||
| 		zerolog.SetGlobalLevel(zerolog.Disabled) | 		zerolog.SetGlobalLevel(zerolog.Disabled) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if cfg.JSONLogs { | ||||||
|  | 		log.Logger = log.Output(os.Stdout) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if !cfg.DisableUpdateCheck && !machineOutput { | 	if !cfg.DisableUpdateCheck && !machineOutput { | ||||||
| 		if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && | 		if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && | ||||||
| 			Version != "dev" { | 			Version != "dev" { | ||||||
|  | |||||||
| @ -173,6 +173,7 @@ tls_cert_path: "" | |||||||
| tls_key_path: "" | tls_key_path: "" | ||||||
| 
 | 
 | ||||||
| log_level: info | log_level: info | ||||||
|  | json_logs: false | ||||||
| 
 | 
 | ||||||
| # Path to a file containg ACL policies. | # Path to a file containg ACL policies. | ||||||
| # ACLs can be defined as YAML or HUJSON. | # ACLs can be defined as YAML or HUJSON. | ||||||
|  | |||||||
| @ -37,6 +37,7 @@ type Config struct { | |||||||
| 	NoisePrivateKeyPath            string | 	NoisePrivateKeyPath            string | ||||||
| 	BaseDomain                     string | 	BaseDomain                     string | ||||||
| 	LogLevel                       zerolog.Level | 	LogLevel                       zerolog.Level | ||||||
|  | 	JSONLogs                       bool | ||||||
| 	DisableUpdateCheck             bool | 	DisableUpdateCheck             bool | ||||||
| 
 | 
 | ||||||
| 	DERP DERPConfig | 	DERP DERPConfig | ||||||
| @ -147,6 +148,7 @@ func LoadConfig(path string, isFile bool) error { | |||||||
| 	viper.SetDefault("tls_client_auth_mode", "relaxed") | 	viper.SetDefault("tls_client_auth_mode", "relaxed") | ||||||
| 
 | 
 | ||||||
| 	viper.SetDefault("log_level", "info") | 	viper.SetDefault("log_level", "info") | ||||||
|  | 	viper.SetDefault("json_logs", false) | ||||||
| 
 | 
 | ||||||
| 	viper.SetDefault("dns_config", nil) | 	viper.SetDefault("dns_config", nil) | ||||||
| 
 | 
 | ||||||
| @ -434,6 +436,7 @@ func GetHeadscaleConfig() (*Config, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logLevel = zerolog.DebugLevel | 		logLevel = zerolog.DebugLevel | ||||||
| 	} | 	} | ||||||
|  | 	jsonLogs := viper.GetBool("json_logs") | ||||||
| 
 | 
 | ||||||
| 	legacyPrefixField := viper.GetString("ip_prefix") | 	legacyPrefixField := viper.GetString("ip_prefix") | ||||||
| 	if len(legacyPrefixField) > 0 { | 	if len(legacyPrefixField) > 0 { | ||||||
| @ -488,6 +491,7 @@ func GetHeadscaleConfig() (*Config, error) { | |||||||
| 		GRPCAllowInsecure:  viper.GetBool("grpc_allow_insecure"), | 		GRPCAllowInsecure:  viper.GetBool("grpc_allow_insecure"), | ||||||
| 		DisableUpdateCheck: viper.GetBool("disable_check_updates"), | 		DisableUpdateCheck: viper.GetBool("disable_check_updates"), | ||||||
| 		LogLevel:           logLevel, | 		LogLevel:           logLevel, | ||||||
|  | 		JSONLogs:           jsonLogs, | ||||||
| 
 | 
 | ||||||
| 		IPPrefixes: prefixes, | 		IPPrefixes: prefixes, | ||||||
| 		PrivateKeyPath: AbsolutePathFromConfigPath( | 		PrivateKeyPath: AbsolutePathFromConfigPath( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user