NewLogFile creates a new LogFile.
(dir, name string)
| 44 | |
| 45 | // NewLogFile creates a new LogFile. |
| 46 | func NewLogFile(dir, name string) (*LogFile, error) { |
| 47 | // If the log exists already we want to append to it. |
| 48 | p := filepath.Join(dir, name+".log") |
| 49 | f, err := os.OpenFile(p, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | fi, err := f.Stat() |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | return &LogFile{ |
| 58 | File: f, |
| 59 | Path: p, |
| 60 | BytesWritten: int(fi.Size()), |
| 61 | }, nil |
| 62 | } |
| 63 | |
| 64 | // Write appends a message to the log file |
| 65 | func (l *LogFile) Write(m *LogMessage) error { |