summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-28 00:03:36 -0600
committerJeff Carr <[email protected]>2024-11-28 00:03:36 -0600
commit9b12c5049e7900b28041415e87700498137219e4 (patch)
treea6bfc0f6a4463f826a428275d074602752fa26c7
parentfe562dbf1bbec118f0dfe2319ec002eff1bab4e2 (diff)
see if http.Flush worksv0.22.8v0.22.7
-rw-r--r--reallog.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/reallog.go b/reallog.go
index fe9062d..9962329 100644
--- a/reallog.go
+++ b/reallog.go
@@ -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
+ }
}
}