From ae1a102882103221ef842176dfd8cb1090d5f591 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sat, 26 Oct 2024 23:09:32 +0900 Subject: 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 --- internal/fmsg/fmsg.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'internal/fmsg/fmsg.go') 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) } -- cgit v1.3.1