mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 09:10:55 +00:00
Update console.go
使用json直接初始化系统变量,代码更简单,并且便于后期扩展
This commit is contained in:
parent
9076ce7d17
commit
b68c814c50
@ -8,30 +8,26 @@ import (
|
||||
|
||||
type ConsoleWriter struct {
|
||||
lg *log.Logger
|
||||
level int
|
||||
Level int `json:"level"`
|
||||
}
|
||||
|
||||
func NewConsole() LoggerInterface {
|
||||
cw := new(ConsoleWriter)
|
||||
cw.lg = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
||||
cw.level = LevelTrace
|
||||
cw.Level = LevelTrace
|
||||
return cw
|
||||
}
|
||||
|
||||
func (c *ConsoleWriter) Init(jsonconfig string) error {
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(jsonconfig), &m)
|
||||
err := json.Unmarshal([]byte(jsonconfig), c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lv, ok := m["level"]; ok {
|
||||
c.level = int(lv.(float64))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConsoleWriter) WriteMsg(msg string, level int) error {
|
||||
if level < c.level {
|
||||
if level < c.Level {
|
||||
return nil
|
||||
}
|
||||
c.lg.Println(msg)
|
||||
|
Loading…
Reference in New Issue
Block a user