Documentation ¶
Index ¶
- Variables
- func AddStyling(message string) string
- func AddVariables(message string) string
- func GetLevelColor(id Level) string
- func GetLevelName(id Level) string
- func GetLevelShortName(id Level) string
- func RemoveStyling(message string) string
- func ReplaceAliases(message string) string
- type Level
- type Logger
- func (l *Logger) Debug(message string)
- func (l *Logger) Error(message string)
- func (l *Logger) Fatal(message string)
- func (l *Logger) Info(message string)
- func (l *Logger) Log(level Level, message string)
- func (l *Logger) Print(message string)
- func (l *Logger) Println(message string)
- func (l *Logger) SetDateFormat(format string)
- func (l *Logger) SetDatetimeFormat(format string)
- func (l *Logger) SetForceStyling(forceStyling bool)
- func (l *Logger) SetLevelColor(id Level, color string)
- func (l *Logger) SetLogFile(file *os.File)
- func (l *Logger) SetLoggingLevel(level Level)
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) SetStyling(styling bool)
- func (l *Logger) SetTimeFormat(format string)
- func (l *Logger) Trace(message string)
- func (l *Logger) Warn(message string)
Constants ¶
This section is empty.
Variables ¶
var ( // Aliases are the aliases for the following placeholders Aliases = map[string]string{ "${date}": "${now:date}", "${time}": "${now:time}", "${datetime}": "${now:datetime}", "${sys:arch}": "${sys:architecture}", "${architecture}": "${sys:architecture}", "${arch}": "${sys:architecture}", "${sys:os}": "${sys:operating_system}", "${operating_system}": "${sys:operating_system}", "${os}": "${sys:operating_system}", "${hostname}": "${sys:hostname}", "${username}": "${sys:username}", "${groupid}": "${sys:groupid}", "${userid}": "${sys:userid}", "${function}": "${caller:function}", "${shortfunction}": "${caller:shortfunction}", "${file}": "${caller:file}", "${line}": "${caller:line}", "${black}": "${fg:black}", "${red}": "${fg:red}", "${green}": "${fg:green}", "${yellow}": "${fg:yellow}", "${blue}": "${fg:blue}", "${purple}": "${fg:purple}", "${cyan}": "${fg:cyan}", "${white}": "${fg:white}", "${gray}": "${fg:gray}", "${brightred}": "${fg:brightred}", "${brightgreen}": "${fg:brightgreen}", "${brightyellow}": "${fg:brightyellow}", "${brightblue}": "${fg:brightblue}", "${brightpurple}": "${fg:brightpurple}", "${brightcyan}": "${fg:brightcyan}", "${brightwhite}": "${fg:brightwhite}", "${bblack}": "${bg:black}", "${bred}": "${bg:red}", "${bgreen}": "${bg:green}", "${byellow}": "${bg:yellow}", "${bblue}": "${bg:blue}", "${bpurple}": "${bg:purple}", "${bcyan}": "${bg:cyan}", "${bwhite}": "${bg:white}", "${bgray}": "${bg:gray}", "${bbrightred}": "${bg:brightred}", "${bbrightgreen}": "${bg:brightgreen}", "${bbrightyellow}": "${bg:brightyellow}", "${bbrightblue}": "${bg:brightblue}", "${bbrightpurple}": "${bg:brightpurple}", "${bbrightcyan}": "${bg:brightcyan}", "${bbrightwhite}": "${bg:brightwhite}", "${bold}": "${effect:bold}", "${dim}": "${effect:dim}", "${underline}": "${effect:underline}", "${blink}": "${effect:blink}", "${inverse}": "${effect:inverse}", "${strikethrough}": "${effect:strikethrough}", "${reset}": "${effect:reset}", } // Variables are the different variables to replace. Variables = map[string]func() string{ "${caller:function}": func() string { pc, _, _, ok := runtime.Caller(4) details := runtime.FuncForPC(pc) if ok && details != nil { return details.Name() } return "" }, "${caller:shortfunction}": func() string { pc, _, _, ok := runtime.Caller(4) details := runtime.FuncForPC(pc) split := strings.Split(details.Name(), ".") if ok && details != nil && len(split) >= 2 { return split[len(split)-1] } return "" }, "${caller:file}": func() string { _, file, _, ok := runtime.Caller(3) split := strings.Split(file, "/") if ok && len(split) >= 1 { return split[len(split)-1] } return "" }, "${caller:line}": func() string { _, _, line, ok := runtime.Caller(3) if ok { return strconv.Itoa(line) } return "0" }, "${level:color}": func() string { return GetLevelColor(CurrentLoggingLevel) }, "${level:lowername}": func() string { return strings.ToLower(GetLevelName(CurrentLoggingLevel)) }, "${level:name}": func() string { return GetLevelName(CurrentLoggingLevel) }, "${level:shortname}": func() string { return GetLevelShortName(CurrentLoggingLevel) }, "${now:date}": func() string { return time.Now().Format(CurrentDateFormat) }, "${now:time}": func() string { return time.Now().Format(CurrentTimeFormat) }, "${now:datetime}": func() string { return time.Now().Format(CurrentDatetimeFormat) }, "${sys:architecture}": func() string { return runtime.GOARCH }, "${sys:hostname}": func() string { hostname, err := os.Hostname() if err != nil { return "" } return hostname }, "${sys:operating_system}": func() string { return runtime.GOOS }, "${sys:username}": func() string { user, err := user.Current() if err != nil { return "" } return user.Username }, "${sys:groupid}": func() string { user, err := user.Current() if err != nil { return "" } return user.Gid }, "${sys:userid}": func() string { user, err := user.Current() if err != nil { return "" } return user.Uid }, } // Styles are the different types of styling. Styles = map[string]string{ "${fg:black}": terminal.BLACK, "${fg:red}": terminal.RED, "${fg:green}": terminal.GREEN, "${fg:yellow}": terminal.YELLOW, "${fg:blue}": terminal.BLUE, "${fg:purple}": terminal.PURPLE, "${fg:cyan}": terminal.CYAN, "${fg:white}": terminal.WHITE, "${fg:gray}": terminal.GRAY, "${fg:brightred}": terminal.BRIGHT_RED, "${fg:brightgreen}": terminal.BRIGHT_GREEN, "${fg:brightyellow}": terminal.BRIGHT_YELLOW, "${fg:brightblue}": terminal.BRIGHT_BLUE, "${fg:brightpurple}": terminal.BRIGHT_PURPLE, "${fg:brightcyan}": terminal.BRIGHT_CYAN, "${fg:brightwhite}": terminal.BRIGHT_WHITE, "${bg:black}": terminal.BG_BLACK, "${bg:red}": terminal.BG_RED, "${bg:green}": terminal.BG_GREEN, "${bg:yellow}": terminal.BG_YELLOW, "${bg:blue}": terminal.BG_BLUE, "${bg:purple}": terminal.BG_PURPLE, "${bg:cyan}": terminal.BG_CYAN, "${bg:white}": terminal.BG_WHITE, "${bg:gray}": terminal.BG_GRAY, "${bg:brightred}": terminal.BG_BRIGHT_RED, "${bg:brightgreen}": terminal.BG_BRIGHT_GREEN, "${bg:brightyellow}": terminal.BG_BRIGHT_YELLOW, "${bg:brightblue}": terminal.BG_BRIGHT_BLUE, "${bg:brightpurple}": terminal.BG_BRIGHT_PURPLE, "${bg:brightcyan}": terminal.BG_BRIGHT_CYAN, "${bg:brightwhite}": terminal.BG_BRIGHT_WHITE, "${effect:bold}": terminal.BOLD, "${effect:dim}": terminal.DIM, "${effect:underline}": terminal.UNDERLINE, "${effect:blink}": terminal.BLINK, "${effect:inverse}": terminal.INVERSE, "${effect:strikethrough}": terminal.STRIKETHROUGH, "${effect:reset}": terminal.RESET, } )
var ( // LevelColors convert a logging level to its color. LevelColors = map[Level]string{ TRACE: terminal.GRAY, DEBUG: terminal.GRAY + terminal.BOLD, INFO: terminal.BLUE + terminal.BOLD, WARN: terminal.YELLOW + terminal.BOLD, ERROR: terminal.RED + terminal.BOLD, FATAL: terminal.BRIGHT_WHITE + terminal.BOLD + terminal.BG_RED, } // LevelNames convert a logging level to its name. LevelNames = map[Level]string{ TRACE: "TRACE", DEBUG: "DEBUG", INFO: "INFO", WARN: "WARN", ERROR: "ERROR", FATAL: "FATAL", } // ShortLevelNames convert a logging level to its short name. ShortLevelNames = map[Level]string{ TRACE: "tra", DEBUG: "dbg", INFO: "inf", WARN: "war", ERROR: "err", FATAL: "fat", } )
var ( CurrentLoggingLevel = NONE CurrentDateFormat = "Jan 02, 2006" CurrentDatetimeFormat = "Jan 02, 2006 15:04:05" CurrentTimeFormat = "15:04:05" ForceStyling = false )
Functions ¶
func AddStyling ¶
AddStyling will add styling into the message.
func AddVariables ¶
AddVariables will add the various variables into the message.
func GetLevelColor ¶
GetLevelColor returns the color of the level.
func GetLevelShortName ¶
GetLevelShortName returns the short name of the level.
func RemoveStyling ¶
RemoveStyling will remove styling from the message.
func ReplaceAliases ¶
ReplaceAliases will replace the aliases with the original placeholder.
Types ¶
type Level ¶
type Level int
Level represents the level of logging - https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/Level.html
const ( // TRACE level designates finer-grained informational events than the DEBUG. TRACE Level = iota // DEBUG level designates fine-grained informational events that are most useful to debug an application. DEBUG // INFO level designates informational messages that highlight the progress of the application at coarse-grained level. INFO // WARN level designates potentially harmful situations. WARN // ERROR level designates error events that might still allow the application to continue running. ERROR // FATAL level designates very severe error events that will presumably lead the application to abort. FATAL // NONE will reset the logging level to nothing. NONE Level = 1337 )
type Logger ¶
type Logger struct { // Styling describes whether the logger should style the logged message. Styling bool // Prefix is the prefix before the logged message. Prefix string // LogFile is the log file to write the messages into. LogFile *os.File }
Logger is represents a logger structure.
func (*Logger) SetDateFormat ¶
SetDateFormat sets the format to use when logging the date.
func (*Logger) SetDatetimeFormat ¶
SetDatetimeFormat sets the format to use when logging the date and time.
func (*Logger) SetForceStyling ¶
SetForceStyling sets to whether it should force the styling render.
func (*Logger) SetLevelColor ¶
SetLevelColor sets the color of the level.
func (*Logger) SetLogFile ¶
SetLogFile will set the log file to write logs into.
func (*Logger) SetLoggingLevel ¶
SetLoggingLevel sets the logging level.
func (*Logger) SetStyling ¶
SetStyling sets the styling setting of the logger.
func (*Logger) SetTimeFormat ¶
SetTimeFormat sets the format to use when logging the time.