diff options
| author | Jeff Carr <[email protected]> | 2024-11-28 00:03:36 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-28 00:03:36 -0600 |
| commit | 9b12c5049e7900b28041415e87700498137219e4 (patch) | |
| tree | a6bfc0f6a4463f826a428275d074602752fa26c7 | |
| parent | fe562dbf1bbec118f0dfe2319ec002eff1bab4e2 (diff) | |
| -rw-r--r-- | reallog.go | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -8,6 +8,7 @@ import ( "io" reallog "log" "net/http" + "time" ) func DaemonMode(b bool) { @@ -20,8 +21,21 @@ func CaptureMode(w io.Writer) { captureMode = w } +var flusher http.Flusher + func HttpMode(w http.ResponseWriter) { + var ok bool httpMode = w + if w == nil { + flusher = nil + return + } + flusher, ok = w.(http.Flusher) + if !ok { + http.Error(w, "Streaming unsupported!", http.StatusInternalServerError) + flusher = nil + return + } } func DaemonShow() bool { @@ -52,8 +66,13 @@ func realPrintln(a ...any) { } } if httpMode != nil { - s := fmt.Sprint(a...) + now := time.Now() + timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work? + s := timestamp + " " + fmt.Sprint(a...) fmt.Fprintln(httpMode, s) + if flusher != nil { + flusher.Flush() // Flush the data to the client + } } } @@ -74,7 +93,13 @@ func realPrintf(s string, a ...any) { } } if httpMode != nil { - fmt.Fprintln(httpMode, fmt.Sprintf(s, a...)) + now := time.Now() + timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work? + s := timestamp + " " + fmt.Sprintf(s, a...) + fmt.Fprintln(httpMode, s) + if flusher != nil { + flusher.Flush() // Flush the data to the client + } } } |
