diff --git a/cmd/ncdu/ncdu.go b/cmd/ncdu/ncdu.go index f326e8ad2..42117ab0d 100644 --- a/cmd/ncdu/ncdu.go +++ b/cmd/ncdu/ncdu.go @@ -929,23 +929,23 @@ func (u *UI) Run() error { return fmt.Errorf("screen init: %w", err) } - // Hijack fs.LogPrint so that it doesn't corrupt the screen. - if logPrint := fs.LogPrint; !log.Redirected() { + // Hijack fs.LogOutput so that it doesn't corrupt the screen. + if logOutput := fs.LogOutput; !log.Redirected() { type log struct { text string level fs.LogLevel } var logs []log - fs.LogPrint = func(level fs.LogLevel, text string) { + fs.LogOutput = func(level fs.LogLevel, text string) { if len(logs) > 100 { logs = logs[len(logs)-100:] } logs = append(logs, log{level: level, text: text}) } defer func() { - fs.LogPrint = logPrint + fs.LogOutput = logOutput for i := range logs { - logPrint(logs[i].level, logs[i].text) + logOutput(logs[i].level, logs[i].text) } }() } diff --git a/cmd/progress.go b/cmd/progress.go index fbdcd19a1..679c1d30d 100644 --- a/cmd/progress.go +++ b/cmd/progress.go @@ -28,12 +28,12 @@ const ( // It returns a func which should be called to stop the stats. func startProgress() func() { stopStats := make(chan struct{}) - oldLogPrint := fs.LogPrint + oldLogOutput := fs.LogOutput oldSyncPrint := operations.SyncPrintf if !log.Redirected() { // Intercept the log calls if not logging to file or syslog - fs.LogPrint = func(level fs.LogLevel, text string) { + fs.LogOutput = func(level fs.LogLevel, text string) { printProgress(fmt.Sprintf("%s %-6s: %s", time.Now().Format(logTimeFormat), level, text)) } @@ -60,7 +60,7 @@ func startProgress() func() { case <-stopStats: ticker.Stop() printProgress("") - fs.LogPrint = oldLogPrint + fs.LogOutput = oldLogOutput operations.SyncPrintf = oldSyncPrint fmt.Println("") return diff --git a/fs/log.go b/fs/log.go index cb30f595b..0b6512b2f 100644 --- a/fs/log.go +++ b/fs/log.go @@ -60,8 +60,8 @@ var LogPrintPid = false // InstallJSONLogger is a hook that --use-json-log calls var InstallJSONLogger = func(logLevel LogLevel) {} -// LogPrint sends the text to the logger of level -var LogPrint = func(level LogLevel, text string) { +// LogOutput sends the text to the logger of level +var LogOutput = func(level LogLevel, text string) { text = fmt.Sprintf("%-6s: %s", level, text) if LogPrintPid { text = fmt.Sprintf("[%d] %s", os.Getpid(), text) @@ -143,7 +143,7 @@ func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{}) if o != nil { out = fmt.Sprintf("%v: %s", o, out) } - LogPrint(level, out) + LogOutput(level, out) } } diff --git a/fs/log/syslog_unix.go b/fs/log/syslog_unix.go index 7d7efe8ee..baa6c613a 100644 --- a/fs/log/syslog_unix.go +++ b/fs/log/syslog_unix.go @@ -51,7 +51,7 @@ func startSysLog() bool { } log.SetFlags(0) log.SetOutput(w) - fs.LogPrint = func(level fs.LogLevel, text string) { + fs.LogOutput = func(level fs.LogLevel, text string) { switch level { case fs.LogLevelEmergency: _ = w.Emerg(text) diff --git a/fs/log/systemd_unix.go b/fs/log/systemd_unix.go index cf78d35a8..22c82ad11 100644 --- a/fs/log/systemd_unix.go +++ b/fs/log/systemd_unix.go @@ -26,7 +26,7 @@ func startSystemdLog() bool { } log.SetFlags(flags) // TODO: Use the native journal.Print approach rather than a custom implementation - fs.LogPrint = func(level fs.LogLevel, text string) { + fs.LogOutput = func(level fs.LogLevel, text string) { text = fmt.Sprintf("<%s>%-6s: %s", systemdLogPrefix(level), level, text) _ = log.Output(4, text) }