From 95ae2688a2645d2c87911767af32a89505c65f56 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 19 Dec 2019 12:29:03 +0000 Subject: [PATCH] add formatters --- debug/log/log.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/debug/log/log.go b/debug/log/log.go index 374023b1..3d2a123b 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -2,6 +2,7 @@ package log import ( + "encoding/json" "time" ) @@ -11,7 +12,7 @@ var ( // DefaultLog logger DefaultLog = NewLog() // Default formatter - DefaultFormat = func(r Record) string { return r.Message.(string) } + DefaultFormat = TextFormat ) // 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 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) +}