27 lines
594 B
Go
27 lines
594 B
Go
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'})
|
|
}
|