refactor: initial default logger

pull/200/head
moonD4rk 2 years ago
parent 1214bf8342
commit cc4edc5cb6
No known key found for this signature in database
GPG Key ID: 5AB6217E08D39ABA
  1. 5
      cmd/hack-browser-data/main.go
  2. 17
      log/log.go

@ -40,11 +40,8 @@ func Execute() {
HideHelpCommand: true, HideHelpCommand: true,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if verbose { if verbose {
log.Init("debug") log.SetVerbose()
} else {
log.Init("notice")
} }
browsers, err := browser.PickBrowsers(browserName, profilePath) browsers, err := browser.PickBrowsers(browserName, profilePath)
if err != nil { if err != nil {
log.Error(err) log.Error(err)

@ -8,19 +8,20 @@ import (
var std = &slog.SugaredLogger{} var std = &slog.SugaredLogger{}
func Init(l string) { func init() {
if l == "debug" { std = newStdLogger(slog.NoticeLevel)
std = newStdLogger(slog.DebugLevel) }
} else {
std = newStdLogger(slog.NoticeLevel) // SetVerbose set log level to debug
} func SetVerbose() {
std = newStdLogger(slog.DebugLevel)
} }
const template = "[{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n" const template = "[{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n"
// NewStdLogger instance // newStdLogger is a new std logger
func newStdLogger(level slog.Level) *slog.SugaredLogger { 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.SetName("stdLogger")
sl.ReportCaller = true sl.ReportCaller = true
sl.CallerSkip = 7 sl.CallerSkip = 7

Loading…
Cancel
Save