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,
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)

@ -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

Loading…
Cancel
Save