Skip to content

Commit

Permalink
Add logger verbosity config
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 7, 2023
1 parent de217eb commit 671ebdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions enduro.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is the configuration file valid for the development environment.

verbosity = 2
debug = true
debugListen = "127.0.0.1:9001"

Expand Down
2 changes: 1 addition & 1 deletion internal/collection/goa.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (w *goaWrapper) Download(ctx context.Context, p *goacollection.DownloadPayl
}

loc := bu.ResolveReference(rel).String()
w.logger.Info("Sending request to Archivematica Storage Service.", "loc", loc)
w.logger.V(1).Info("Sending request to Archivematica Storage Service.", "loc", loc)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, loc, nil)
if err != nil {
return nil, nil, &goacollection.CollectionNotfound{ID: p.ID, Message: "not_found"}
Expand Down
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func main() {
}

// Logging configuration.
logger := log.New(os.Stderr, log.WithName(appName), log.WithDebug(config.Debug))
logger := log.New(os.Stderr,
log.WithName(appName),
log.WithDebug(config.Debug),
log.WithLevel(config.Verbosity),
)
defer log.Sync(logger)

logger.Info("Starting...", "version", version, "pid", os.Getpid())
Expand Down Expand Up @@ -332,6 +336,7 @@ func main() {
}

type configuration struct {
Verbosity int
Debug bool
DebugListen string
API api.Config
Expand Down Expand Up @@ -373,16 +378,16 @@ func readConfig(v *viper.Viper, config *configuration, configFile string) (found
found = true
}
if found && err != nil {
return found, fmt.Errorf("Failed to read configuration file: %w", err)
return found, fmt.Errorf("failed to read configuration file: %w", err)
}

err = v.Unmarshal(config)
if err != nil {
return found, fmt.Errorf("Failed to unmarshal configuration: %w", err)
return found, fmt.Errorf("failed to unmarshal configuration: %w", err)
}

if err := config.Validate(); err != nil {
return found, fmt.Errorf("Failed to validate the provided config: %w", err)
return found, fmt.Errorf("failed to validate the provided config: %w", err)
}

return found, nil
Expand Down

0 comments on commit 671ebdd

Please sign in to comment.