mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:00:54 +00:00
Merge pull request #473 from cloudaice/logs-feature
diffrent level logs display diffrent color
This commit is contained in:
commit
edf7982567
@ -6,6 +6,25 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Brush func(string) string
|
||||||
|
|
||||||
|
func NewBrush(color string) Brush {
|
||||||
|
pre := "\033["
|
||||||
|
reset := "\033[0m"
|
||||||
|
return func(text string) string {
|
||||||
|
return pre + color + "m" + text + reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var colors = []Brush{
|
||||||
|
NewBrush("1;36"), // Trace cyan
|
||||||
|
NewBrush("1;34"), // Debug blue
|
||||||
|
NewBrush("1;32"), // Info green
|
||||||
|
NewBrush("1;33"), // Warn yellow
|
||||||
|
NewBrush("1;31"), // Error red
|
||||||
|
NewBrush("1;35"), // Critical purple
|
||||||
|
}
|
||||||
|
|
||||||
// ConsoleWriter implements LoggerInterface and writes messages to terminal.
|
// ConsoleWriter implements LoggerInterface and writes messages to terminal.
|
||||||
type ConsoleWriter struct {
|
type ConsoleWriter struct {
|
||||||
lg *log.Logger
|
lg *log.Logger
|
||||||
@ -35,7 +54,7 @@ func (c *ConsoleWriter) WriteMsg(msg string, level int) error {
|
|||||||
if level < c.Level {
|
if level < c.Level {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.lg.Println(msg)
|
c.lg.Println(colors[level](msg))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user