You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
594 B
26 lines
594 B
package flog |
|
|
|
import ( |
|
"fmt" |
|
"io" |
|
"strconv" |
|
"text/tabwriter" |
|
) |
|
|
|
// TextFormatter logs in a human readable format |
|
type TextFormatter struct{} |
|
|
|
// FormatMessage implements LogFormatType |
|
func (l TextFormatter) FormatMessage(w io.Writer, entry LogEntry) { |
|
fmt.Fprintln(w, entry.Level, entry.Time.Format(`[2006-01-02 15:04:05]`), entry.Message) |
|
|
|
if len(entry.StackTrace) > 0 { |
|
tw := tabwriter.NewWriter(w, 1, 4, 4, ' ', 0) |
|
for _, v := range entry.StackTrace { |
|
fmt.Fprint(tw, ` `, v.Function, "\t", v.File+`:`+strconv.Itoa(v.Line), "\n") |
|
} |
|
tw.Flush() |
|
} |
|
|
|
w.Write([]byte{'\n'}) |
|
}
|
|
|