From b3a6550ac26762d9f51ebfaaf11475ac1856d633 Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Wed, 27 Mar 2024 14:13:33 -0700 Subject: [PATCH] set logging levels --- .gitea/workflows/lint.yaml | 2 +- cmd/cli/main.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/lint.yaml b/.gitea/workflows/lint.yaml index 55492fc..256b293 100644 --- a/.gitea/workflows/lint.yaml +++ b/.gitea/workflows/lint.yaml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.21.7" + go-version: "1.21.1" cache: false - name: Check out code diff --git a/cmd/cli/main.go b/cmd/cli/main.go index fd26565..f7759b0 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -5,6 +5,7 @@ import ( "os" "flag" "log" + "log/slog" _ "fmt" _ "gopkg.in/yaml.v3" "decl/internal/resource" @@ -12,6 +13,14 @@ _ "gopkg.in/yaml.v3" func main() { + var programLevel = new(slog.LevelVar) + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})) + slog.SetDefault(logger) + if debugLogging,ok := os.LookupEnv("DECL_DEBUG"); ok && debugLogging != "" { + programLevel.Set(slog.LevelDebug) + } else { + programLevel.Set(slog.LevelError) + } file := flag.String("resource-file", "", "Resource file path") resourceUri := flag.String("import-resource", "", "Add an existing resource")