github.com/koko1123/flow-go-1@v0.29.6/module/util/log.go (about) 1 package util 2 3 import ( 4 "github.com/rs/zerolog" 5 ) 6 7 func LogProgress(msg string, total int, logger *zerolog.Logger) func(currentIndex int) { 8 logThreshold := float64(10) 9 return func(currentIndex int) { 10 percentage := float64(100) 11 if total > 0 { 12 percentage = (float64(currentIndex+1) / float64(total)) * 100. // currentIndex+1 assuming zero based indexing 13 } 14 15 // report every 10 percent 16 if percentage >= logThreshold { 17 logger.Info().Msgf("%s completion percentage: %v percent", msg, int(percentage)) 18 logThreshold += 10 19 } 20 } 21 }