mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 22:50:56 +00:00
Fix init for alils.go
This commit is contained in:
parent
ed1d2c7f6e
commit
48a98ec1a5
@ -37,6 +37,8 @@ type aliLSWriter struct {
|
||||
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),
|
||||
|
Loading…
Reference in New Issue
Block a user