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 58 59 60 61 62
|
package log
import (
"strconv"
"time"
"github.com/evilsocket/islazy/tui"
)
var (
// Tokens is a map of the tokens that can be used in Format
// to insert values returned by the execution of a callback.
Tokens = map[string]func() string{
"{date}": func() string {
return time.Now().Format(DateFormat)
},
"{time}": func() string {
return time.Now().Format(TimeFormat)
},
"{datetime}": func() string {
return time.Now().Format(DateTimeFormat)
},
"{level:value}": func() string {
return strconv.Itoa(int(currLevel))
},
"{level:name}": func() string {
return LevelNames[currLevel]
},
"{level:color}": func() string {
return LevelColors[currLevel]
},
"{message}": func() string {
return currMessage
},
}
// Effects is a map of the tokens that can be used in Format to
// change the properties of the text.
Effects = map[string]string{
"{bold}": tui.BOLD,
"{dim}": tui.DIM,
"{red}": tui.RED,
"{green}": tui.GREEN,
"{blue}": tui.BLUE,
"{yellow}": tui.YELLOW,
"{f:black}": tui.FOREBLACK,
"{f:white}": tui.FOREWHITE,
"{b:darkgray}": tui.BACKDARKGRAY,
"{b:red}": tui.BACKRED,
"{b:green}": tui.BACKGREEN,
"{b:yellow}": tui.BACKYELLOW,
"{b:lightblue}": tui.BACKLIGHTBLUE,
"{reset}": tui.RESET,
}
// DateFormat is the default date format being used when filling the {date} log token.
DateFormat = "06-Jan-02"
// TimeFormat is the default time format being used when filling the {time} or {datetime} log tokens.
TimeFormat = "15:04:05"
// DateTimeFormat is the default date and time format being used when filling the {datetime} log token.
DateTimeFormat = "2006-01-02 15:04:05"
// Format is the default format being used when logging.
Format = "{datetime} {level:color}{level:name}{reset} {message}"
)
|