diff options
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) { |
