Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger verbosity config #551

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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