NewInternalLogger creates a logger that stores logs in the specified cache directory This is designed for TUI applications where stdout logging would interfere with the UI.
(level Level, cacheDir string)
| 59 | // NewInternalLogger creates a logger that stores logs in the specified cache directory |
| 60 | // This is designed for TUI applications where stdout logging would interfere with the UI. |
| 61 | func NewInternalLogger(level Level, cacheDir string) (*Logger, error) { |
| 62 | // Use the provided cache directory for log files |
| 63 | logsDir := cacheDir |
| 64 | if logsDir == "" { |
| 65 | // Fallback to current directory if no cache dir provided |
| 66 | logsDir = "." |
| 67 | } |
| 68 | |
| 69 | if err := os.MkdirAll(logsDir, 0o750); err != nil { |
| 70 | // If we can't create cache directory, fall back to current directory |
| 71 | logsDir = "." |
| 72 | } |
| 73 | |
| 74 | logFile := filepath.Join(logsDir, "pvetui.log") |
| 75 | config := &Config{ |
| 76 | Level: level, |
| 77 | LogToFile: true, |
| 78 | LogFile: logFile, |
| 79 | } |
| 80 | |
| 81 | return NewLogger(config) |
| 82 | } |
| 83 | |
| 84 | // DefaultConfig returns a default logger configuration. |
| 85 | func DefaultConfig() *Config { |