// NewLiteralLogHandler will create a new LiteralLogHandler. func NewLiteralLogHandler(options *core.PipelineOptions) (*LiteralLogHandler, error) { var logger *util.Logger if options.Debug { logger = util.RootLogger() } else { logger = util.NewLogger() logger.Formatter = &reporter.LiteralFormatter{} logger.Level = log.InfoLevel } return &LiteralLogHandler{l: logger, options: options}, nil }
// emitProgress will keep emitting progress until a value is send into the // returned channel. func emitProgress(counter *util.CounterReader, total int64, logger *util.Logger) chan<- bool { stop := make(chan bool) go func(stop chan bool, counter *util.CounterReader, total int64) { prev := int64(-1) for { current := counter.Count() percentage := (100 * current) / total select { case <-stop: logger.Infof("\rDownloading: %3d%%\n", percentage) return default: if percentage != prev { logger.Infof("\rDownloading: %3d%%", percentage) prev = percentage } time.Sleep(1 * time.Second) } } }(stop, counter, total) return stop }