Skip to content

Commit

Permalink
customize log level (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: gang.liu <[email protected]>
  • Loading branch information
izturn authored Aug 23, 2023
1 parent 83a4f22 commit bd02ed5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"log/slog"

"github.com/argoproj-labs/rollouts-plugin-trafficrouter-contour/pkg/plugin"
Expand All @@ -20,8 +21,12 @@ var handshakeConfig = goPlugin.HandshakeConfig{
MagicCookieValue: "trafficrouter",
}

var lvl = flag.Int("l", int(slog.LevelInfo), "the logging level for 'log/slog', (default: 0)")

func main() {
utils.InitLogger()
flag.Parse()

utils.InitLogger(slog.Level(*lvl))

rpcPluginImp := &plugin.RpcPlugin{}

Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func Must1[T any](t T, err error) T {
return t
}

func InitLogger() {
lvl := &slog.LevelVar{}
lvl.Set(slog.LevelDebug)
func InitLogger(lvl slog.Level) {
lvlVar := &slog.LevelVar{}
lvlVar.Set(lvl)
opts := slog.HandlerOptions{
Level: lvl,
Level: lvlVar,
}

attrs := []slog.Attr{
Expand Down

0 comments on commit bd02ed5

Please sign in to comment.