diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index ff26680..c2b28a0 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.go @@ -40,11 +40,8 @@ func Execute() { HideHelpCommand: true, Action: func(c *cli.Context) error { if verbose { - log.Init("debug") - } else { - log.Init("notice") + log.SetVerbose() } - browsers, err := browser.PickBrowsers(browserName, profilePath) if err != nil { log.Error(err) diff --git a/log/log.go b/log/log.go index cbcf023..4bd48fe 100644 --- a/log/log.go +++ b/log/log.go @@ -8,19 +8,20 @@ import ( var std = &slog.SugaredLogger{} -func Init(l string) { - if l == "debug" { - std = newStdLogger(slog.DebugLevel) - } else { - std = newStdLogger(slog.NoticeLevel) - } +func init() { + std = newStdLogger(slog.NoticeLevel) +} + +// SetVerbose set log level to debug +func SetVerbose() { + std = newStdLogger(slog.DebugLevel) } const template = "[{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n" -// NewStdLogger instance +// newStdLogger is a new std logger func newStdLogger(level slog.Level) *slog.SugaredLogger { - return slog.NewSugaredLogger(os.Stdout, level).Configure(func(sl *slog.SugaredLogger) { + return slog.NewSugaredLogger(os.Stdout, level).Config(func(sl *slog.SugaredLogger) { sl.SetName("stdLogger") sl.ReportCaller = true sl.CallerSkip = 7