feat: enhance log reading with ANSI color stripping and comprehensive documentation

- Add newLogReader function with optional ANSI color code stripping
- Implement logReaderNoColor() and logReaderRaw() methods for different use cases
- Add comprehensive documentation for logReader struct and all related methods
- Add extensive test coverage with 16+ test cases covering edge cases

The new functionality allows consumers to choose between raw log data
(with ANSI color codes) or stripped content (without color codes),
making logs more suitable for different processing pipelines and
display environments.
This commit is contained in:
Cuong Manh Le
2025-09-08 16:46:16 +07:00
committed by Cuong Manh Le
parent 37ddbd90f1
commit 4be262156f
3 changed files with 378 additions and 7 deletions
+2 -2
View File
@@ -283,7 +283,7 @@ func (p *prog) registerControlServerHandler() {
}
}))
p.cs.register(viewLogsPath, http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
lr, err := p.logReader()
lr, err := p.logReaderRaw()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
@@ -309,7 +309,7 @@ func (p *prog) registerControlServerHandler() {
w.WriteHeader(http.StatusServiceUnavailable)
return
}
r, err := p.logReader()
r, err := p.logReaderNoColor()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return