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