diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index 2bf2f9a..1116fcc 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -98,4 +98,4 @@ output: password: secret # mysql database user password database: birdnet # mysql database name host: localhost # mysql database host - port: 3306 # mysql database port \ No newline at end of file + port: 3306 # mysql database port diff --git a/internal/httpcontroller/fileserver.go b/internal/httpcontroller/fileserver.go index 32221b0..7518c21 100644 --- a/internal/httpcontroller/fileserver.go +++ b/internal/httpcontroller/fileserver.go @@ -1,9 +1,11 @@ package httpcontroller import ( + "bufio" "io/fs" "mime" "net/http" + "os" "path/filepath" "strings" @@ -34,3 +36,30 @@ func customFileServer(e *echo.Echo, fileSystem fs.FS, root string) { fileServer.ServeHTTP(w, r) }))) } + +// readWebLog reads the content of the web.log file from the root directory and returns it as a string. +// It returns an error if there is an issue opening or reading the file. +func readWebLog() (string, error) { + // Open the web.log file + file, err := os.Open("webui.log") + if err != nil { + return "", err + } + defer file.Close() + + var content string + scanner := bufio.NewScanner(file) + + // Read the file line by line and append each line to the content string + for scanner.Scan() { + content += scanner.Text() + "\n" + } + + // Check if there was an error during scanning + if err := scanner.Err(); err != nil { + return "", err + } + + // Return the content of the file + return content, nil +} diff --git a/internal/httpcontroller/handlers.go b/internal/httpcontroller/handlers.go index 29bb1f2..d423bdd 100644 --- a/internal/httpcontroller/handlers.go +++ b/internal/httpcontroller/handlers.go @@ -387,3 +387,19 @@ func (s *Server) serveSpectrogramHandler(c echo.Context) error { // Serve the spectrogram image file return c.File(spectrogramPath) } + +// getLogsHandler handles GET requests to the /logs endpoint. +// It reads the content of the webui.log file and renders the logs view with the content. +func (s *Server) getLogsHandler(c echo.Context) error { + // Read the content of web.log + logContent, err := readWebLog() + if err != nil { + // Return an HTTP error if there is an issue reading the file + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read web.log: "+err.Error()) + } + + // Render the logs view and pass the logContent as data + return c.Render(http.StatusOK, "logs", map[string]interface{}{ + "LogContent": logContent, + }) +} diff --git a/internal/httpcontroller/routes.go b/internal/httpcontroller/routes.go index 32e3061..12aa76c 100644 --- a/internal/httpcontroller/routes.go +++ b/internal/httpcontroller/routes.go @@ -66,6 +66,7 @@ func (s *Server) initRoutes() { // Other static routes. s.Echo.Static("/clips", "clips") + s.Echo.GET("/logs", s.getLogsHandler) // Additional handlers. s.Echo.GET("/top-birds", s.topBirdsHandler) @@ -75,7 +76,6 @@ func (s *Server) initRoutes() { s.Echo.GET("/search", s.searchHandler) s.Echo.GET("/spectrogram", s.serveSpectrogramHandler) - // Handle both GET and DELETE requests for the /note route s.Echo.Add("GET", "/note", s.getNoteHandler) s.Echo.Add("DELETE", "/note", s.deleteNoteHandler) diff --git a/views/logs.html b/views/logs.html index a6d725d..a1dd3cb 100644 --- a/views/logs.html +++ b/views/logs.html @@ -1,5 +1,57 @@ {{define "logs"}} -Nothing here yet .. + + -{{end}} \ No newline at end of file + + + BirdNET-Go Logs + + + + + + + + + + + + +
+
+ {{ template "header" . }} +
+ + +
+
+ + {{if .LogContent}} +
{{.LogContent}}
+ {{else}} + It didn't work + {{end}} +
+
+ +
+
+
+ + {{ template "sidebar" . }} + + + + + + +{{end}}