/
githubmirror
/
rclone
Обзор
Документация
Войти
/
githubmirror
/
rclone
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cmd/bisync/bilib/output.go
30 строк
626 B
Nick Craig-Wood
bisync: fix race when CaptureOutput is used concurrently #8815
26 сен 2025, 16:54
26 сен 2025, 16:54
2f6a6c8
Код
Авторство
О чём код?
// Package bilib provides common stuff for bisync and bisync_test package bilib import ( "bytes" "log/slog" "sync" "github.com/rclone/rclone/fs/log" ) // CaptureOutput runs a function capturing its output at log level INFO. func CaptureOutput(fun func()) []byte { var mu sync.Mutex buf := &bytes.Buffer{} oldLevel := log.Handler.SetLevel(slog.LevelInfo) log.Handler.SetOutput(func(level slog.Level, text string) { mu.Lock() defer mu.Unlock() buf.WriteString(text) }) defer func() { log.Handler.ResetOutput() log.Handler.SetLevel(oldLevel) }() fun() mu.Lock() defer mu.Unlock() return buf.Bytes() }