-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b12231
commit eee0476
Showing
9 changed files
with
60 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Change: Switch to official logging library | ||
|
||
Since there have been a structured logger part of the Go standard library we | ||
thought it's time to replace the library with that. Be aware that log messages | ||
should change a little bit. | ||
|
||
https://github.com/promhippie/dockerhub_exporter/issues/186 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
package command | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
"strings" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/promhippie/dockerhub_exporter/pkg/config" | ||
) | ||
|
||
func setupLogger(cfg *config.Config) log.Logger { | ||
var logger log.Logger | ||
|
||
func setupLogger(cfg *config.Config) *slog.Logger { | ||
if cfg.Logs.Pretty { | ||
logger = log.NewSyncLogger( | ||
log.NewLogfmtLogger(os.Stdout), | ||
) | ||
} else { | ||
logger = log.NewSyncLogger( | ||
log.NewJSONLogger(os.Stdout), | ||
return slog.New( | ||
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: loggerLevel(cfg), | ||
}), | ||
) | ||
} | ||
|
||
return slog.New( | ||
slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: loggerLevel(cfg), | ||
}), | ||
) | ||
} | ||
|
||
func loggerLevel(cfg *config.Config) slog.Leveler { | ||
switch strings.ToLower(cfg.Logs.Level) { | ||
case "error": | ||
logger = level.NewFilter(logger, level.AllowError()) | ||
return slog.LevelError | ||
case "warn": | ||
logger = level.NewFilter(logger, level.AllowWarn()) | ||
return slog.LevelWarn | ||
case "info": | ||
logger = level.NewFilter(logger, level.AllowInfo()) | ||
return slog.LevelInfo | ||
case "debug": | ||
logger = level.NewFilter(logger, level.AllowDebug()) | ||
default: | ||
logger = level.NewFilter(logger, level.AllowInfo()) | ||
return slog.LevelDebug | ||
} | ||
|
||
return log.With( | ||
logger, | ||
"ts", log.DefaultTimestampUTC, | ||
) | ||
return slog.LevelInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters