add formatters

This commit is contained in:
Asim Aslam 2019-12-19 12:29:03 +00:00
parent 2bcfb85613
commit 95ae2688a2

View File

@ -2,6 +2,7 @@
package log package log
import ( import (
"encoding/json"
"time" "time"
) )
@ -11,7 +12,7 @@ var (
// DefaultLog logger // DefaultLog logger
DefaultLog = NewLog() DefaultLog = NewLog()
// Default formatter // Default formatter
DefaultFormat = func(r Record) string { return r.Message.(string) } DefaultFormat = TextFormat
) )
// Log is debug log interface for reading and writing logs // Log is debug log interface for reading and writing logs
@ -42,3 +43,14 @@ type Stream interface {
// Format is a function which formats the output // Format is a function which formats the output
type FormatFunc func(Record) string type FormatFunc func(Record) string
// TextFormat returns text format
func TextFormat(r Record) string {
return r.Message.(string)
}
// JSONFormat is a json Format func
func JSONFormat(r Record) string {
b, _ := json.Marshal(r)
return string(b)
}