forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trail.go
45 lines (40 loc) · 834 Bytes
/
trail.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
package uadmin
import (
"fmt"
"log"
"strings"
"github.com/dekunt/uadmin/colors"
)
// Reporting Levels
const (
DEBUG = 0
WORKING = 1
INFO = 2
OK = 3
WARNING = 4
ERROR = 5
)
var trailTag = map[int]string{
DEBUG: colors.Debug,
WORKING: colors.Working,
INFO: colors.Info,
OK: colors.OK,
WARNING: colors.Warning,
ERROR: colors.Error,
}
// Trail prints to the log
func Trail(level int, msg interface{}, i ...interface{}) {
if level >= ReportingLevel {
message := fmt.Sprint(msg)
if level != WORKING && !strings.HasSuffix(message, "\n") {
message += "\n"
} else if level == WORKING && !strings.HasPrefix(message, "\r") {
message = message + "\r"
}
if ReportTimeStamp {
log.Printf(trailTag[level]+message, i...)
} else {
fmt.Printf(trailTag[level]+message, i...)
}
}
}