Fix time machine output with progress bar (linux only)

This has a log formatter that clears each line before printing overflow information.

TODO: fix for windows as well
This commit is contained in:
marco 2024-01-26 15:16:42 +01:00
parent ad34b57419
commit c755a0015e

View file

@ -13,6 +13,20 @@ var logFormatter log.Formatter
var LogOutput *lumberjack.Logger //io.Writer
var logLevel log.Level
type CustomFormatter struct {
log.TextFormatter
}
func (f *CustomFormatter) Format(entry *log.Entry) ([]byte, error) {
// Clear line escape sequence
clearLine := "\r\033[K"
result, err := f.TextFormatter.Format(entry)
if err != nil {
return nil, err
}
return append([]byte(clearLine), result...), nil
}
func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level, maxSize int, maxFiles int, maxAge int, compress *bool, forceColors bool) error {
/*Configure logs*/
if cfgMode == "file" {
@ -46,7 +60,7 @@ func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level
}
logLevel = cfgLevel
log.SetLevel(logLevel)
logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}
logFormatter = &CustomFormatter{TextFormatter: log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}}
log.SetFormatter(logFormatter)
return nil
}