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