Skip to content

Commit

Permalink
revise log
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong committed Feb 2, 2024
1 parent dcca863 commit 7b259ca
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
6 changes: 0 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func (c *Config) Load(loaders ...Loader) error {
// Merged to empty map to convert to lower case.
maps.Merge(provider.values, values)
c.providers = append(c.providers, provider)

slog.Info(
"Configuration has been loaded.",
"loader", loader,
)
}

return nil
Expand Down Expand Up @@ -212,7 +207,6 @@ func (c *Config) Watch(ctx context.Context) error { //nolint:cyclop,funlen,gocog
)
}

slog.Info("Watching configuration change.", "loader", watcher)
if err := watcher.Watch(ctx, onChange); err != nil {
errChan <- fmt.Errorf("watch configuration change: %w", err)
cancel()
Expand Down
2 changes: 1 addition & 1 deletion default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func Get[T any](path string) T { //nolint:ireturn
var value T
if err := Unmarshal(path, &value); err != nil {
slog.Error(
slog.Warn(
"Could not read config, return empty value instead.",
"error", err,
"path", path,
Expand Down
2 changes: 1 addition & 1 deletion default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestGet_error(t *testing.T) {
log.SetFlags(0)

assert.True(t, !konf.Get[bool]("config"))
expected := "ERROR Could not read config, return empty value instead." +
expected := "WARN Could not read config, return empty value instead." +
" error=\"decode: cannot parse '' as bool: strconv.ParseBool: parsing \\\"string\\\": invalid syntax\"" +
" path=config type=bool\n"
assert.Equal(t, expected, buf.String())
Expand Down
6 changes: 3 additions & 3 deletions provider/file/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (f File) Watch(ctx context.Context, onChange func(map[string]any)) error {
}
defer func() {
if err := watcher.Close(); err != nil {
slog.Error("Error when closing file watcher.", "file", f.path, "error", err)
slog.WarnContext(ctx, "Error when closing file watcher.", "file", f.path, "error", err)
}
}()

Expand Down Expand Up @@ -73,7 +73,7 @@ func (f File) Watch(ctx context.Context, onChange func(map[string]any)) error {
case event.Has(fsnotify.Create) || event.Has(fsnotify.Write):
values, err := f.Load()
if err != nil {
slog.Error("Error when reloading config file", "file", f.path, "error", err)
slog.WarnContext(ctx, "Error when reloading config file", "file", f.path, "error", err)

continue
}
Expand All @@ -85,7 +85,7 @@ func (f File) Watch(ctx context.Context, onChange func(map[string]any)) error {
return nil
}

slog.Error("Error when watching file", "file", f.path, "error", err)
slog.WarnContext(ctx, "Error when watching file", "file", f.path, "error", err)

case <-ctx.Done():
return nil
Expand Down

0 comments on commit 7b259ca

Please sign in to comment.