1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 11:21:29 +00:00
Beego/logs/console.go
1fei b68c814c50 Update console.go
使用json直接初始化系统变量,代码更简单,并且便于后期扩展
2013-12-19 18:15:00 +08:00

48 lines
697 B
Go

package logs
import (
"encoding/json"
"log"
"os"
)
type ConsoleWriter struct {
lg *log.Logger
Level int `json:"level"`
}
func NewConsole() LoggerInterface {
cw := new(ConsoleWriter)
cw.lg = log.New(os.Stdout, "", log.Ldate|log.Ltime)
cw.Level = LevelTrace
return cw
}
func (c *ConsoleWriter) Init(jsonconfig string) error {
err := json.Unmarshal([]byte(jsonconfig), c)
if err != nil {
return err
}
return nil
}
func (c *ConsoleWriter) WriteMsg(msg string, level int) error {
if level < c.Level {
return nil
}
c.lg.Println(msg)
return nil
}
func (c *ConsoleWriter) Destroy() {
}
func (c *ConsoleWriter) Flush() {
}
func init() {
Register("console", NewConsole)
}