mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 22:30:49 +00:00
Add noColor option for console logger
- Also added simple test
This commit is contained in:
parent
85c0fcd335
commit
7f888e3d18
@ -47,8 +47,9 @@ var colors = []brush{
|
||||
|
||||
// consoleWriter implements LoggerInterface and writes messages to terminal.
|
||||
type consoleWriter struct {
|
||||
lg *log.Logger
|
||||
Level int `json:"level"`
|
||||
lg *log.Logger
|
||||
Level int `json:"level"`
|
||||
NoColor bool `json:"noColor"`
|
||||
}
|
||||
|
||||
// NewConsole create ConsoleWriter returning as LoggerInterface.
|
||||
@ -75,7 +76,7 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
|
||||
return nil
|
||||
}
|
||||
msg = formatLogTime(when) + msg
|
||||
if runtime.GOOS == "windows" {
|
||||
if runtime.GOOS == "windows" || c.NoColor {
|
||||
c.lg.Println(msg)
|
||||
return nil
|
||||
}
|
||||
|
@ -42,3 +42,10 @@ func TestConsole(t *testing.T) {
|
||||
log2.SetLogger("console", `{"level":3}`)
|
||||
testConsoleCalls(log2)
|
||||
}
|
||||
|
||||
// Test console without color
|
||||
func TestConsoleNoColor(t *testing.T) {
|
||||
log := NewLogger(100)
|
||||
log.SetLogger("console", `{"noColor":true}`)
|
||||
testConsoleCalls(log)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user