Fix init for alils.go

This commit is contained in:
IamCathal 2020-08-24 20:39:53 +01:00
parent ed1d2c7f6e
commit 48a98ec1a5
1 changed files with 21 additions and 6 deletions

View File

@ -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),