mirror of
https://github.com/rclone/rclone.git
synced 2025-07-23 23:05:54 +02:00
This removes logrus which is not developed any more and replaces it with the new log/slog from the Go standard library. It implements its own slog Handler which is backwards compatible with all of rclone's previous logging modes.
25 lines
537 B
Go
25 lines
537 B
Go
// Package bilib provides common stuff for bisync and bisync_test
|
|
package bilib
|
|
|
|
import (
|
|
"bytes"
|
|
"log/slog"
|
|
|
|
"github.com/rclone/rclone/fs/log"
|
|
)
|
|
|
|
// CaptureOutput runs a function capturing its output at log level INFO.
|
|
func CaptureOutput(fun func()) []byte {
|
|
buf := &bytes.Buffer{}
|
|
oldLevel := log.Handler.SetLevel(slog.LevelInfo)
|
|
log.Handler.SetOutput(func(level slog.Level, text string) {
|
|
buf.WriteString(text)
|
|
})
|
|
defer func() {
|
|
log.Handler.ResetOutput()
|
|
log.Handler.SetLevel(oldLevel)
|
|
}()
|
|
fun()
|
|
return buf.Bytes()
|
|
}
|