mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 05:10:55 +00:00
Fix init for alils.go
This commit is contained in:
parent
ed1d2c7f6e
commit
48a98ec1a5
@ -32,11 +32,13 @@ type Config struct {
|
|||||||
// aliLSWriter implements LoggerInterface.
|
// aliLSWriter implements LoggerInterface.
|
||||||
// Writes messages in keep-live tcp connection.
|
// Writes messages in keep-live tcp connection.
|
||||||
type aliLSWriter struct {
|
type aliLSWriter struct {
|
||||||
store *LogStore
|
store *LogStore
|
||||||
group []*LogGroup
|
group []*LogGroup
|
||||||
withMap bool
|
withMap bool
|
||||||
groupMap map[string]*LogGroup
|
groupMap map[string]*LogGroup
|
||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
|
UseCustomFormatter bool
|
||||||
|
CustomFormatter func(*logs.LogMsg) string
|
||||||
Config
|
Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +50,14 @@ func NewAliLS() logs.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init parses config and initializes struct
|
// 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)
|
json.Unmarshal([]byte(jsonConfig), c)
|
||||||
|
|
||||||
@ -135,6 +144,12 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
|
|||||||
lg = c.group[0]
|
lg = c.group[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.UseCustomFormatter {
|
||||||
|
content = c.CustomFormatter(lm)
|
||||||
|
} else {
|
||||||
|
content = c.Format(lm)
|
||||||
|
}
|
||||||
|
|
||||||
c1 := &LogContent{
|
c1 := &LogContent{
|
||||||
Key: proto.String("msg"),
|
Key: proto.String("msg"),
|
||||||
Value: proto.String(content),
|
Value: proto.String(content),
|
||||||
|
Loading…
Reference in New Issue
Block a user