mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
fix: migrate from github.com/rs/zerolog to golang-native log/slog (#3405)
* fix: migrate from github.com/rs/zerolog to golang-native log/slog We have been using zerolog for a really long time. golang now has structured logging using slog. Best to move to this in interests of long-term support. This is a tech debt item. Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> * fix: a few changes on top Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> * fix: address comments Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> --------- Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d5779cfec8
commit
b1842ab9e0
@@ -5,12 +5,12 @@ package cli
|
||||
|
||||
import (
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
zerr "zotregistry.dev/zot/errors"
|
||||
"zotregistry.dev/zot/pkg/exporter/api"
|
||||
"zotregistry.dev/zot/pkg/log"
|
||||
)
|
||||
|
||||
// metadataConfig reports metadata after parsing, which we use to track
|
||||
@@ -59,21 +59,23 @@ func NewExporterCmd() *cobra.Command {
|
||||
func loadConfiguration(config *api.Config, configPath string) {
|
||||
viper.SetConfigFile(configPath)
|
||||
|
||||
logger := log.NewLogger("info", "")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Panic().Err(err).Str("config", configPath).Msg("failed to read configuration")
|
||||
logger.Panic().Err(err).Str("config", configPath).Msg("failed to read configuration")
|
||||
}
|
||||
|
||||
metaData := &mapstructure.Metadata{}
|
||||
if err := viper.Unmarshal(&config, metadataConfig(metaData)); err != nil {
|
||||
log.Panic().Err(err).Str("config", configPath).Msg("failed to unmarshal config")
|
||||
logger.Panic().Err(err).Str("config", configPath).Msg("failed to unmarshal config")
|
||||
}
|
||||
|
||||
if len(metaData.Keys) == 0 {
|
||||
log.Panic().Err(zerr.ErrBadConfig).Str("config", configPath).Msg("bad configuration")
|
||||
logger.Panic().Err(zerr.ErrBadConfig).Str("config", configPath).Msg("bad configuration")
|
||||
}
|
||||
|
||||
if len(metaData.Unused) > 0 {
|
||||
log.Panic().Err(zerr.ErrBadConfig).Interface("unknown fields", metaData.Unused).
|
||||
logger.Panic().Err(zerr.ErrBadConfig).Interface("unknown fields", metaData.Unused).
|
||||
Str("config", configPath).Msg("bad configuration")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user