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:
parent
ad34b57419
commit
c755a0015e
1 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue