fmsg: support temporarily withholding output
All checks were successful
test / test (push) Successful in 31s

Trying to print to a shared stdout is a terrible idea. This change makes it possible to withhold output for the lifetime of the sandbox.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-10-26 23:09:32 +09:00
parent 093e99d062
commit ae1a102882
11 changed files with 105 additions and 32 deletions

View File

@@ -4,38 +4,40 @@ package fmsg
import (
"log"
"os"
"sync/atomic"
)
var (
std = log.New(os.Stdout, "fortify: ", 0)
warn = log.New(os.Stderr, "fortify: ", 0)
verbose = new(atomic.Bool)
)
var std = log.New(os.Stderr, "fortify: ", 0)
func SetPrefix(prefix string) {
prefix += ": "
std.SetPrefix(prefix)
warn.SetPrefix(prefix)
std.SetPrefix(prefix)
}
func Print(v ...any) {
warn.Print(v...)
dequeueOnce.Do(dequeue)
queueSync.Add(1)
msgbuf <- dPrint(v)
}
func Printf(format string, v ...any) {
warn.Printf(format, v...)
dequeueOnce.Do(dequeue)
queueSync.Add(1)
msgbuf <- &dPrintf{format, v}
}
func Println(v ...any) {
warn.Println(v...)
dequeueOnce.Do(dequeue)
queueSync.Add(1)
msgbuf <- dPrintln(v)
}
func Fatal(v ...any) {
warn.Fatal(v...)
Print(v...)
Exit(1)
}
func Fatalf(format string, v ...any) {
warn.Fatalf(format, v...)
Printf(format, v...)
Exit(1)
}