summaryrefslogtreecommitdiff
path: root/reallog.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-07 01:23:43 -0600
committerJeff Carr <[email protected]>2024-11-07 01:23:43 -0600
commitef61eb494b42a7bc226de1edc114579ce530abdd (patch)
tree0bd23b52a8aae23806d8cdc9896936c39cd07728 /reallog.go
parent2b11a4e334f465aef868d6c1bf3f1a7c9dfd5c27 (diff)
try allowing switching to writing to httpv0.22.2
Diffstat (limited to 'reallog.go')
-rw-r--r--reallog.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/reallog.go b/reallog.go
index 9191fa8..a2c9a76 100644
--- a/reallog.go
+++ b/reallog.go
@@ -3,15 +3,20 @@ package log
// implements 'daemon' mode so switches to fmt
// instead of log so that timestamps are not printed twice
-import (
+import (
"fmt"
reallog "log"
+ "net/http"
)
func DaemonMode(b bool) {
daemonMode = b
}
+func HttpMode(w http.ResponseWriter) {
+ httpMode = w
+}
+
func DaemonShow() {
if daemonMode {
fmt.Println("daemonMode=true")
@@ -21,18 +26,26 @@ func DaemonShow() {
}
func realPrintln(a ...any) {
- if daemonMode {
- fmt.Println(a...)
+ if httpMode == nil {
+ if daemonMode {
+ fmt.Println(a...)
+ } else {
+ reallog.Println(a...)
+ }
} else {
- reallog.Println(a...)
+ fmt.Fprintln(httpMode, a...)
}
}
func realPrintf(s string, a ...any) {
- if daemonMode {
- fmt.Printf(s, a...)
+ if httpMode == nil {
+ if daemonMode {
+ fmt.Printf(s, a...)
+ } else {
+ reallog.Printf(s, a...)
+ }
} else {
- reallog.Printf(s, a...)
+ fmt.Fprintln(httpMode, fmt.Sprintf(s, a...))
}
}
@@ -44,8 +57,8 @@ func realSprintf(s string, a ...any) string {
return fmt.Sprintf(s, a...)
}
-func realSprintln(s string, a ...any) string {
- return fmt.Sprintf(s, a...) + "\n"
+func realSprintln(a ...any) string {
+ return fmt.Sprintln(a...)
}
func realFatalln(a ...any) {