diff --git a/pkg/logs/alils/alils.go b/pkg/logs/alils/alils.go index 2c83e4ee..2300f8f8 100644 --- a/pkg/logs/alils/alils.go +++ b/pkg/logs/alils/alils.go @@ -32,11 +32,13 @@ type Config struct { // aliLSWriter implements LoggerInterface. // Writes messages in keep-live tcp connection. type aliLSWriter struct { - store *LogStore - group []*LogGroup - withMap bool - groupMap map[string]*LogGroup - lock *sync.Mutex + store *LogStore + group []*LogGroup + withMap bool + groupMap map[string]*LogGroup + lock *sync.Mutex + UseCustomFormatter bool + CustomFormatter func(*logs.LogMsg) string Config } @@ -48,7 +50,14 @@ func NewAliLS() logs.Logger { } // Init parses config and initializes struct -func (c *aliLSWriter) Init(jsonConfig string) (err error) { +func (c *aliLSWriter) Init(jsonConfig string, LogFormatter ...func(*logs.LogMsg) string) (err error) { + + for _, elem := range LogFormatter { + if elem != nil { + c.UseCustomFormatter = true + c.CustomFormatter = elem + } + } json.Unmarshal([]byte(jsonConfig), c) @@ -135,6 +144,12 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error { lg = c.group[0] } + if c.UseCustomFormatter { + content = c.CustomFormatter(lm) + } else { + content = c.Format(lm) + } + c1 := &LogContent{ Key: proto.String("msg"), Value: proto.String(content),