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

fix: log duration of padlog steps #3439

Merged
merged 1 commit into from Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions internal/middleware/logging/logging.go
Expand Up @@ -20,9 +20,7 @@ func Log(title string, next middleware.Action) middleware.Action {
return func(ctx *context.Context) error {
start := time.Now()
defer func() {
if took := time.Since(start).Round(time.Second); took > 0 {
log.Info(faint.Render(fmt.Sprintf("took: %s", took)))
}
logDuration(start)
log.ResetPadding()
}()
log.Infof(bold.Render(title))
Expand All @@ -34,11 +32,21 @@ func Log(title string, next middleware.Action) middleware.Action {
// PadLog pretty prints the given action and its title with an increased padding.
func PadLog(title string, next middleware.Action) middleware.Action {
return func(ctx *context.Context) error {
defer log.ResetPadding()
start := time.Now()
defer func() {
logDuration(start)
log.ResetPadding()
}()
log.ResetPadding()
log.IncreasePadding()
log.Infof(bold.Render(title))
log.IncreasePadding()
return next(ctx)
}
}

func logDuration(start time.Time) {
if took := time.Since(start).Round(time.Second); took > 0 {
log.Info(faint.Render(fmt.Sprintf("took: %s", took)))
}
}