Unified · Split
| @@ -38,7 +38,13 @@ func (m *LogFormatter) Format(entry *log.Entry) ([]byte, error) { · 37 unmodified lines | |||
| 38 | 38 | ||
| 39 | timestamp := entry.Time.Format("2006-01-02 15:04:05") | 39 | timestamp := entry.Time.Format("2006-01-02 15:04:05") |
| 40 | message := strings.TrimRight(entry.Message, "\r\n") | 40 | message := strings.TrimRight(entry.Message, "\r\n") |
| 41 | formatted := fmt.Sprintf("[%s] [%s] [%s:%d] %s\n", timestamp, entry.Level, filepath.Base(entry.Caller.File), entry.Caller.Line, message) | 41 | |
| 42 | var formatted string | ||
| 43 | if entry.Caller != nil { | ||
| 44 | formatted = fmt.Sprintf("[%s] [%s] [%s:%d] %s\n", timestamp, entry.Level, filepath.Base(entry.Caller.File), entry.Caller.Line, message) | ||
| 45 | } else { | ||
| 46 | formatted = fmt.Sprintf("[%s] [%s] %s\n", timestamp, entry.Level, message) | ||
| 47 | } | ||
| 42 | buffer.WriteString(formatted) | 48 | buffer.WriteString(formatted) |
| 43 | 49 | ||
| 44 | return buffer.Bytes(), nil | 50 | return buffer.Bytes(), nil |