@@ -23,6 +23,7 @@ const (
2323 githubTokenEnvVar = "GITHUB_TOKEN"
2424 githubClientIDEnvVar = "GITHUB_CLIENT_ID"
2525 githubClientSecretEnvVar = "GITHUB_CLIENT_SECRET"
26+ logLevelEnvVar = "LOG_LEVEL"
2627)
2728
2829const (
@@ -68,6 +69,9 @@ const (
6869
6970 // Pub/Sub Config
7071 ConfigCrawlPubSubTopic = "crawl-events"
72+
73+ // Log Config
74+ ConfigLogLevel = "log-level"
7175)
7276
7377func loadConfig (ctx context.Context , args []string ) (* viper.Viper , error ) {
@@ -111,6 +115,7 @@ func loadConfig(ctx context.Context, args []string) (*viper.Viper, error) {
111115 v .BindEnv (ConfigGithubToken , githubTokenEnvVar )
112116 v .BindEnv (ConfigGithubClientID , githubClientIDEnvVar )
113117 v .BindEnv (ConfigGithubClientSecret , githubClientSecretEnvVar )
118+ v .BindEnv (ConfigLogLevel , logLevelEnvVar )
114119
115120 // Read from config.
116121 if err := readViperConfig (ctx , v ); err != nil {
@@ -120,6 +125,8 @@ func loadConfig(ctx context.Context, args []string) (*viper.Viper, error) {
120125 // Set defaults based on other configs
121126 setDefaults (v )
122127
128+ log .SetLevel (v .GetString (ConfigLogLevel ))
129+
123130 log .Debug (ctx , "config values loaded" , "values" , v .AllSettings ())
124131 return v , nil
125132}
@@ -173,6 +180,7 @@ func buildFlags() *pflag.FlagSet {
173180 flags .String (ConfigGAERemoteAPI , "" , "Remoteapi endpoint for App Engine Search. Defaults to serviceproxy-dot-${project}.appspot.com." )
174181 flags .Float64 (ConfigTraceSamplerFraction , 0.1 , "Fraction of the requests sampled by the trace API." )
175182 flags .Float64 (ConfigTraceSamplerMaxQPS , 5 , "Max number of requests sampled every second by the trace API." )
183+ flags .String (ConfigLogLevel , "info" , "Determine which level of logs to print." )
176184
177185 return flags
178186}
0 commit comments