History

Resolve relative logsDir to executable directory in FileRequestLogger

Luis Pater committed 1 year agov5.1.17

Commit 4e67cd41 parent 0449fef1 file · +11 −0Browse files

Unified · Split

internal/logging/request_logger.go+11−0
@@ -103,6 +103,17 @@ type FileRequestLogger struct { · 102 unmodified lines
103103 // Returns:
104104 // - *FileRequestLogger: A new file-based request logger instance
105105 func NewFileRequestLogger(enabled bool, logsDir string) *FileRequestLogger {
106+ // Resolve logsDir relative to the executable directory when it's not absolute.
107+ if !filepath.IsAbs(logsDir) {
108+ if exePath, err := os.Executable(); err == nil {
109+ // Resolve symlinks to get the real executable path
110+ if realExe, errEvalSymlinks := filepath.EvalSymlinks(exePath); errEvalSymlinks == nil {
111+ exePath = realExe
112+ }
113+ execDir := filepath.Dir(exePath)
114+ logsDir = filepath.Join(execDir, logsDir)
115+ }
116+ }
106117 return &FileRequestLogger{
107118 enabled: enabled,
108119 logsDir: logsDir,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t