aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/fmsg/fmsg.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-26 23:09:32 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-26 23:09:32 +0900
commitae1a102882103221ef842176dfd8cb1090d5f591 (patch)
tree16f34686bac5564998a9a0e84be96d83ed3e59bd /internal/fmsg/fmsg.go
parent093e99d062f873dc9d83b1f76a156c1ee4275c57 (diff)
fmsg: support temporarily withholding output
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>
Diffstat (limited to 'internal/fmsg/fmsg.go')
-rw-r--r--internal/fmsg/fmsg.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/internal/fmsg/fmsg.go b/internal/fmsg/fmsg.go
index c72913f8..dbe590bf 100644
--- a/internal/fmsg/fmsg.go
+++ b/internal/fmsg/fmsg.go
@@ -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)
}