Commit bf943ddb by Dieter Plaetinck

actually make use of the LogLevel type

why else would it be defined?
and this is sane anyway.
parent 3f5b33b0
......@@ -46,8 +46,8 @@ var (
// ConsoleWriter implements LoggerInterface and writes messages to terminal.
type ConsoleWriter struct {
lg *log.Logger
Level int `json:"level"`
Formatting bool `json:"formatting"`
Level LogLevel `json:"level"`
Formatting bool `json:"formatting"`
}
// create ConsoleWriter returning as LoggerInterface.
......@@ -63,7 +63,7 @@ func (cw *ConsoleWriter) Init(config string) error {
return json.Unmarshal([]byte(config), cw)
}
func (cw *ConsoleWriter) WriteMsg(msg string, skip, level int) error {
func (cw *ConsoleWriter) WriteMsg(msg string, skip int, level LogLevel) error {
if cw.Level > level {
return nil
}
......@@ -82,11 +82,11 @@ func (_ *ConsoleWriter) Flush() {
func (_ *ConsoleWriter) Destroy() {
}
func printConsole(level int, msg string) {
func printConsole(level LogLevel, msg string) {
consoleWriter.WriteMsg(msg, 0, level)
}
func printfConsole(level int, format string, v ...interface{}) {
func printfConsole(level LogLevel, format string, v ...interface{}) {
consoleWriter.WriteMsg(fmt.Sprintf(format, v...), 0, level)
}
......
......@@ -41,7 +41,7 @@ type FileLogWriter struct {
startLock sync.Mutex // Only one log can write to the file
Level int `json:"level"`
Level LogLevel `json:"level"`
}
// an *os.File writer with locker.
......@@ -132,7 +132,7 @@ func (w *FileLogWriter) docheck(size int) {
}
// write logger message into file.
func (w *FileLogWriter) WriteMsg(msg string, skip, level int) error {
func (w *FileLogWriter) WriteMsg(msg string, skip int, level LogLevel) error {
if level < w.Level {
return nil
}
......
......@@ -99,7 +99,7 @@ func Close() {
type LogLevel int
const (
TRACE = iota
TRACE LogLevel = iota
DEBUG
INFO
WARN
......@@ -111,7 +111,7 @@ const (
// LoggerInterface represents behaviors of a logger provider.
type LoggerInterface interface {
Init(config string) error
WriteMsg(msg string, skip, level int) error
WriteMsg(msg string, skip int, level LogLevel) error
Destroy()
Flush()
}
......@@ -132,8 +132,9 @@ func Register(name string, log loggerType) {
}
type logMsg struct {
skip, level int
msg string
skip int
level LogLevel
msg string
}
// Logger is default logger in beego application.
......@@ -141,7 +142,7 @@ type logMsg struct {
type Logger struct {
adapter string
lock sync.Mutex
level int
level LogLevel
msg chan *logMsg
outputs map[string]LoggerInterface
quit chan bool
......@@ -188,7 +189,7 @@ func (l *Logger) DelLogger(adapter string) error {
return nil
}
func (l *Logger) writerMsg(skip, level int, msg string) error {
func (l *Logger) writerMsg(skip int, level LogLevel, msg string) error {
if l.level > level {
return nil
}
......
......@@ -39,7 +39,7 @@ func (sw *SyslogWriter) Init(config string) error {
return nil
}
func (sw *SyslogWriter) WriteMsg(msg string, skip, level int) error {
func (sw *SyslogWriter) WriteMsg(msg string, skip int, level LogLevel) error {
var err error
switch level {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment