Skip to content

Commit

Permalink
Fixed the default log location (#273)
Browse files Browse the repository at this point in the history
- Fixed the detection for the default log location
  • Loading branch information
cjlapao authored Jan 13, 2025
1 parent 4eb8fc4 commit 042bbf1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -432,14 +433,14 @@ func GetSystemLogs() restapi.ControllerHandler {

logPath := cfg.GetKey(constants.LOG_FILE_PATH_ENV_VAR)
if logPath == "" {
logPath = "."
logPath = filepath.Dir(os.Args[0])
}
logFile := filepath.Join(logPath, "prldevops.log")

content, err := os.ReadFile(logFile)
if err != nil {
ReturnApiError(ctx, w, models.ApiErrorResponse{
Message: "Failed to read log file: " + err.Error(),
Message: fmt.Sprintf("Failed to read log file %s: %v", logFile, err.Error()),
Code: http.StatusBadRequest,
})
return
Expand All @@ -465,7 +466,7 @@ func StreamSystemLogs() restapi.ControllerHandler {
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true // You might want to make this more restrictive
return true
},
}

Expand Down Expand Up @@ -509,14 +510,15 @@ func StreamSystemLogs() restapi.ControllerHandler {

logPath := cfg.GetKey(constants.LOG_FILE_PATH_ENV_VAR)
if logPath == "" {
logPath = "."
logPath = filepath.Dir(os.Args[0])
}

logFile := filepath.Join(logPath, "prldevops.log")

// Open the file
file, err := os.Open(logFile)
if err != nil {
ws.WriteMessage(websocket.TextMessage, []byte("Error opening log file: "+err.Error()))
ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("Failed to open log file %s: %v", logFile, err.Error())))
return
}
defer file.Close()
Expand Down

0 comments on commit 042bbf1

Please sign in to comment.