diff options
| author | Jeff Carr <[email protected]> | 2024-11-07 01:23:43 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-07 01:23:43 -0600 |
| commit | ef61eb494b42a7bc226de1edc114579ce530abdd (patch) | |
| tree | 0bd23b52a8aae23806d8cdc9896936c39cd07728 /reallog.go | |
| parent | 2b11a4e334f465aef868d6c1bf3f1a7c9dfd5c27 (diff) | |
try allowing switching to writing to httpv0.22.2
Diffstat (limited to 'reallog.go')
| -rw-r--r-- | reallog.go | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -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) { |
