forked from youpenglai/goutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.go
52 lines (41 loc) · 868 Bytes
/
console.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package logger
import (
"os"
)
const (
ConsoleBlack = "\x1b[30m"
ConsoleRed = "\x1b[31m"
ConsoleGreen = "\x1b[32m"
ConsoleYellow = "\x1b[33m"
ConsoleBlue = "\x1b[34m"
ConsoleMagenta = "\x1b[35m"
ConsoleCyan ="\x1b[36m"
ConsoleWhite = "\x1b[37m"
ConsoleReset = "\x1b[0m"
)
func ColorText(text, color string) string {
return color + text + ConsoleReset
}
type ConsoleWriter struct {
writer *os.File
}
func NewConsoleWriter(opts LoggerOpts) LoggerWriter {
return &ConsoleWriter{
writer: os.Stdout,
}
}
func (cw *ConsoleWriter) MatchPrefix(prefix string) bool {
return true
}
func (cw *ConsoleWriter) Colorful() bool {
return true
}
func (cw *ConsoleWriter) Write(b []byte) (int, error) {
return cw.writer.Write(b)
}
func (cw *ConsoleWriter) Flush() {
cw.writer.Sync()
}
func init() {
RegisterLoggerWriter(LoggerConsole, NewConsoleWriter)
}