aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/fmsg/fmsg.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-21 20:47:02 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-21 20:47:02 +0900
commit42e0b168e3d75389dfb968aebf9f5629d64782f9 (patch)
treee6b430205213c62bc06275c6d84e6037d40f5c3f /internal/fmsg/fmsg.go
parent380d1f45851b7dffb963c51da96a17ba41f3cfb8 (diff)
fmsg: produce all output through fmsg
The behaviour of print functions from package fmt is not thread safe. Functions provided by fmsg wrap around Logger methods. This makes prefix much cleaner and makes it easy to deal with future changes to logging. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/fmsg/fmsg.go')
-rw-r--r--internal/fmsg/fmsg.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/fmsg/fmsg.go b/internal/fmsg/fmsg.go
index 40d34108..c72913f8 100644
--- a/internal/fmsg/fmsg.go
+++ b/internal/fmsg/fmsg.go
@@ -1,2 +1,41 @@
// Package fmsg provides various functions for output messages.
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)
+)
+
+func SetPrefix(prefix string) {
+ prefix += ": "
+ std.SetPrefix(prefix)
+ warn.SetPrefix(prefix)
+}
+
+func Print(v ...any) {
+ warn.Print(v...)
+}
+
+func Printf(format string, v ...any) {
+ warn.Printf(format, v...)
+}
+
+func Println(v ...any) {
+ warn.Println(v...)
+}
+
+func Fatal(v ...any) {
+ warn.Fatal(v...)
+}
+
+func Fatalf(format string, v ...any) {
+ warn.Fatalf(format, v...)
+}