| 34 | } |
| 35 | |
| 36 | func openLogFile(path string) (*os.File, error) { |
| 37 | if path == "" { |
| 38 | return nil, nil |
| 39 | } |
| 40 | |
| 41 | // Ensure the directory exists |
| 42 | dir := filepath.Dir(path) |
| 43 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | |
| 47 | // Try to open the file, create if not exists, and append to it |
| 48 | f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | return f, nil |
| 53 | } |
| 54 | |
| 55 | func (l *Logger) SetLogFile(accessPath, errorPath string) error { |
| 56 | l.mu.Lock() |