Debian Codegraph @

log/format.go

raw
1 package log
2
3 import (
4 "strconv"
5 "time"
6
7 "github.com/evilsocket/islazy/tui"
8 )
9
10 var (
11 // Tokens is a map of the tokens that can be used in Format
12 // to insert values returned by the execution of a callback.
13 Tokens = map[string]func() string{
14 "{date}": func() string {
15 return time.Now().Format(DateFormat)
16 },
17 "{time}": func() string {
18 return time.Now().Format(TimeFormat)
19 },
20 "{datetime}": func() string {
21 return time.Now().Format(DateTimeFormat)
22 },
23 "{level:value}": func() string {
24 return strconv.Itoa(int(currLevel))
25 },
26 "{level:name}": func() string {
27 return LevelNames[currLevel]
28 },
29 "{level:color}": func() string {
30 return LevelColors[currLevel]
31 },
32 "{message}": func() string {
33 return currMessage
34 },
35 }
36 // Effects is a map of the tokens that can be used in Format to
37 // change the properties of the text.
38 Effects = map[string]string{
39 "{bold}": tui.BOLD,
40 "{dim}": tui.DIM,
41 "{red}": tui.RED,
42 "{green}": tui.GREEN,
43 "{blue}": tui.BLUE,
44 "{yellow}": tui.YELLOW,
45 "{f:black}": tui.FOREBLACK,
46 "{f:white}": tui.FOREWHITE,
47 "{b:darkgray}": tui.BACKDARKGRAY,
48 "{b:red}": tui.BACKRED,
49 "{b:green}": tui.BACKGREEN,
50 "{b:yellow}": tui.BACKYELLOW,
51 "{b:lightblue}": tui.BACKLIGHTBLUE,
52 "{reset}": tui.RESET,
53 }
54 // DateFormat is the default date format being used when filling the {date} log token.
55 DateFormat = "06-Jan-02"
56 // TimeFormat is the default time format being used when filling the {time} or {datetime} log tokens.
57 TimeFormat = "15:04:05"
58 // DateTimeFormat is the default date and time format being used when filling the {datetime} log token.
59 DateTimeFormat = "2006-01-02 15:04:05"
60 // Format is the default format being used when logging.
61 Format = "{datetime} {level:color}{level:name}{reset} {message}"
62 )