mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 03:40:55 +00:00
Merge pull request #1638 from pjoe/log_console_nocolor
Add noColor option for console logger
This commit is contained in:
commit
bd79972d85
@ -49,6 +49,7 @@ var colors = []brush{
|
|||||||
type consoleWriter struct {
|
type consoleWriter struct {
|
||||||
lg *log.Logger
|
lg *log.Logger
|
||||||
Level int `json:"level"`
|
Level int `json:"level"`
|
||||||
|
Color bool `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConsole create ConsoleWriter returning as LoggerInterface.
|
// NewConsole create ConsoleWriter returning as LoggerInterface.
|
||||||
@ -56,6 +57,7 @@ func NewConsole() Logger {
|
|||||||
cw := &consoleWriter{
|
cw := &consoleWriter{
|
||||||
lg: log.New(os.Stdout, "", 0),
|
lg: log.New(os.Stdout, "", 0),
|
||||||
Level: LevelDebug,
|
Level: LevelDebug,
|
||||||
|
Color: true,
|
||||||
}
|
}
|
||||||
return cw
|
return cw
|
||||||
}
|
}
|
||||||
@ -75,7 +77,7 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
msg = formatLogTime(when) + msg
|
msg = formatLogTime(when) + msg
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" || !c.Color {
|
||||||
c.lg.Println(msg)
|
c.lg.Println(msg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,10 @@ func TestConsole(t *testing.T) {
|
|||||||
log2.SetLogger("console", `{"level":3}`)
|
log2.SetLogger("console", `{"level":3}`)
|
||||||
testConsoleCalls(log2)
|
testConsoleCalls(log2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test console without color
|
||||||
|
func TestConsoleNoColor(t *testing.T) {
|
||||||
|
log := NewLogger(100)
|
||||||
|
log.SetLogger("console", `{"color":false}`)
|
||||||
|
testConsoleCalls(log)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user