generated from nathanwoodburn/go-webserver-template
feat: Add better log displaying
All checks were successful
Build Docker / BuildSite (push) Successful in 1m2s
All checks were successful
Build Docker / BuildSite (push) Successful in 1m2s
This commit is contained in:
parent
8942a3a285
commit
52e1a761fb
13
main.go
13
main.go
@ -77,6 +77,19 @@ func getHandler(relPath string, w http.ResponseWriter, r *http.Request) {
|
|||||||
logData, err := os.ReadFile(logFilePath)
|
logData, err := os.ReadFile(logFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logData = []byte("No log file found")
|
logData = []byte("No log file found")
|
||||||
|
} else {
|
||||||
|
// Keep any lines that don't contain test and invert line order
|
||||||
|
lines := bytes.Split(logData, []byte("\n"))
|
||||||
|
var newLines [][]byte
|
||||||
|
for i := len(lines) - 1; i >= 0; i-- {
|
||||||
|
if !bytes.Contains(lines[i], []byte("Test")) {
|
||||||
|
newLines = append(newLines, lines[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add latest test line (excluding the last line which is empty)
|
||||||
|
newLines = append(newLines, lines[len(lines)-2])
|
||||||
|
|
||||||
|
logData = bytes.Join(newLines, []byte("\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a map to hold the data
|
// Create a map to hold the data
|
||||||
|
@ -17,3 +17,11 @@ Sat 22 Jun 2024 17:33:25 AEST - Test
|
|||||||
Sat 22 Jun 2024 17:33:37 AEST - Test
|
Sat 22 Jun 2024 17:33:37 AEST - Test
|
||||||
Sat 22 Jun 2024 17:33:51 AEST - Test
|
Sat 22 Jun 2024 17:33:51 AEST - Test
|
||||||
Sat 22 Jun 2024 17:36:21 AEST - Test
|
Sat 22 Jun 2024 17:36:21 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:49:37 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:49:54 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:50:17 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:50:36 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:50:49 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:51:04 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:51:16 AEST - Test
|
||||||
|
Sat 22 Jun 2024 17:51:45 AEST - Test
|
||||||
|
Loading…
Reference in New Issue
Block a user