| @@ -98,20 +98,18 @@ type FileRequestLogger struct { · 97 unmodified lines |
| 98 | // | 98 | // |
| 99 | // Parameters: | 99 | // Parameters: |
| 100 | // - enabled: Whether request logging should be enabled | 100 | // - enabled: Whether request logging should be enabled |
| 101 | // - logsDir: The directory where log files should be stored | 101 | // - logsDir: The directory where log files should be stored (can be relative) |
| | 102 | // - configDir: The directory of the configuration file; when logsDir is |
| | 103 | // relative, it will be resolved relative to this directory |
| 102 | // | 104 | // |
| 103 | // Returns: | 105 | // Returns: |
| 104 | // - *FileRequestLogger: A new file-based request logger instance | 106 | // - *FileRequestLogger: A new file-based request logger instance |
| 105 | func NewFileRequestLogger(enabled bool, logsDir string) *FileRequestLogger { | 107 | func NewFileRequestLogger(enabled bool, logsDir string, configDir string) *FileRequestLogger { |
| 106 | // Resolve logsDir relative to the executable directory when it's not absolute. | 108 | // Resolve logsDir relative to the configuration file directory when it's not absolute. |
| 107 | if !filepath.IsAbs(logsDir) { | 109 | if !filepath.IsAbs(logsDir) { |
| 108 | if exePath, err := os.Executable(); err == nil { | 110 | // If configDir is provided, resolve logsDir relative to it. |
| 109 | // Resolve symlinks to get the real executable path | 111 | if configDir != "" { |
| 110 | if realExe, errEvalSymlinks := filepath.EvalSymlinks(exePath); errEvalSymlinks == nil { | 112 | logsDir = filepath.Join(configDir, logsDir) |
| 111 | exePath = realExe | | |
| 112 | } | | |
| 113 | execDir := filepath.Dir(exePath) | | |
| 114 | logsDir = filepath.Join(execDir, logsDir) | | |
| 115 | } | 113 | } |
| 116 | } | 114 | } |
| 117 | return &FileRequestLogger{ | 115 | return &FileRequestLogger{ |