Refactor log implementation

- use []byte instead of unnecessary string conversions
- make LogManager.Broadcast private
- make LogManager.GetHistory public
- add tests
This commit is contained in:
Benson Wong
2024-10-31 12:16:54 -07:00
parent 0f133f5b74
commit 8cf2a389d8
4 changed files with 92 additions and 19 deletions

View File

@@ -61,9 +61,9 @@ func (pm *ProxyManager) streamLogs(w http.ResponseWriter, r *http.Request) {
skipHistory := r.URL.Query().Has("skip")
if !skipHistory {
// Send history first
history := pm.logMonitor.getHistory()
if history != "" {
fmt.Fprint(w, history)
history := pm.logMonitor.GetHistory()
if len(history) != 0 {
w.Write(history)
flusher.Flush()
}
}
@@ -76,7 +76,7 @@ func (pm *ProxyManager) streamLogs(w http.ResponseWriter, r *http.Request) {
for {
select {
case msg := <-ch:
fmt.Fprint(w, msg)
w.Write(msg)
flusher.Flush()
case <-notify:
return