@@ -10,6 +10,7 @@ import (
1010 "net/http"
1111 "os"
1212 "os/signal"
13+ "strings"
1314 "syscall"
1415 "time"
1516
@@ -65,8 +66,13 @@ func main() {
6566
6667 // init logging
6768 log .SetFlags (log .LstdFlags | log .Lshortfile | log .LUTC )
68- opts := slog.HandlerOptions {Level : slog .LevelInfo }
69+ logLevelStr := getEnvOrDefault ("LOG_LEVEL" , "INFO" )
70+ level , msg := parseLogLevel (logLevelStr )
71+ opts := slog.HandlerOptions {Level : level }
6972 slog .SetDefault (slog .New (slog .NewJSONHandler (os .Stdout , & opts )))
73+ if msg != "" {
74+ slog .Warn (msg )
75+ }
7076
7177 var ghAppPrivateKey []byte
7278 if b64Key := os .Getenv ("GH_APP_PRIVATE_KEY" ); b64Key != "" {
@@ -220,3 +226,18 @@ func createK8sConfig(kubeconfig string) (*rest.Config, error) {
220226 }
221227 return clientcmd .BuildConfigFromFlags ("" , homeDir + "/.kube/config" )
222228}
229+
230+ func parseLogLevel (logLevel string ) (slog.Level , string ) {
231+ switch strings .ToUpper (logLevel ) {
232+ case "DEBUG" :
233+ return slog .LevelDebug , ""
234+ case "INFO" :
235+ return slog .LevelInfo , ""
236+ case "WARN" :
237+ return slog .LevelWarn , ""
238+ case "ERROR" :
239+ return slog .LevelError , ""
240+ default :
241+ return slog .LevelInfo , fmt .Sprintf ("%s is an unsupported log level (DEBUG, WARN, INFO, ERROR), using INFO..." , logLevel )
242+ }
243+ }
0 commit comments