forked from op/go-logging
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlog.go
57 lines (49 loc) · 1.15 KB
/
log.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
53
54
55
56
57
// Copyright 2013, Örjan Persson. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logging
import (
"fmt"
"io"
)
type color int
const (
_ = iota + 30
colorRed
colorGreen
colorYellow
_
colorMagenta
colorCyan
)
var (
colors = []string{
CRITICAL: colorSeq(colorMagenta),
ERROR: colorSeq(colorRed),
WARNING: colorSeq(colorYellow),
NOTICE: colorSeq(colorGreen),
DEBUG: colorSeq(colorCyan),
}
boldcolors = []string{
CRITICAL: colorSeqBold(colorMagenta),
ERROR: colorSeqBold(colorRed),
WARNING: colorSeqBold(colorYellow),
NOTICE: colorSeqBold(colorGreen),
DEBUG: colorSeqBold(colorCyan),
}
)
func colorSeq(color color) string {
return fmt.Sprintf("\033[%dm", int(color))
}
func colorSeqBold(color color) string {
return fmt.Sprintf("\033[%d;1m", int(color))
}
func doFmtVerbLevelColor(layout string, level Level, output io.Writer) {
if layout == "bold" {
_, _ = output.Write([]byte(boldcolors[level]))
} else if layout == "reset" {
_, _ = output.Write([]byte("\033[0m"))
} else {
_, _ = output.Write([]byte(colors[level]))
}
}