github.com/goreleaser/goreleaser@v1.25.1/internal/middleware/logging/logging.go (about) 1 package logging 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/caarlos0/log" 8 "github.com/charmbracelet/lipgloss" 9 "github.com/goreleaser/goreleaser/internal/middleware" 10 "github.com/goreleaser/goreleaser/pkg/context" 11 ) 12 13 var ( 14 bold = lipgloss.NewStyle().Bold(true) 15 faint = lipgloss.NewStyle().Italic(true).Faint(true) 16 ) 17 18 // Log pretty prints the given action and its title. 19 func Log(title string, next middleware.Action) middleware.Action { 20 return func(ctx *context.Context) error { 21 start := time.Now() 22 defer func() { 23 logDuration(start) 24 log.ResetPadding() 25 }() 26 log.Infof(bold.Render(title)) 27 log.IncreasePadding() 28 return next(ctx) 29 } 30 } 31 32 // PadLog pretty prints the given action and its title with an increased padding. 33 func PadLog(title string, next middleware.Action) middleware.Action { 34 return func(ctx *context.Context) error { 35 start := time.Now() 36 defer func() { 37 logDuration(start) 38 log.ResetPadding() 39 }() 40 log.ResetPadding() 41 log.IncreasePadding() 42 log.Infof(bold.Render(title)) 43 log.IncreasePadding() 44 return next(ctx) 45 } 46 } 47 48 func logDuration(start time.Time) { 49 if took := time.Since(start).Round(time.Second); took > 0 { 50 log.Info(faint.Render(fmt.Sprintf("took: %s", took))) 51 } 52 }