Documentation ¶
Index ¶
- Constants
- Variables
- func CallerName(skip int) string
- func Color(entry *logrus.Entry, formatter CustomFormatterI, s string) string
- func NewApacheCommonLogFormatterDefault() *loggerAVA.Logger
- func NewLoggerApacheCombinedLogFormatterDefault() *loggerAVA.Logger
- func NewLoggerApacheErrorLogFormatterDefault() *loggerAVA.Logger
- func NewLoggerCommonLogfileFormatterDefault() *loggerAVA.Logger
- func NewLoggerRFC3164Default() *loggerAVA.Logger
- func NewLoggerRFC5424Default() *loggerAVA.Logger
- func NewLoggerTextFormatterDefault() *loggerAVA.Logger
- func WindowsEnableNativeANSI(stderr bool) *errorAVA.Error
- func WindowsNativeANSI() bool
- type ApacheCombinedFormatter
- func (f *ApacheCombinedFormatter) Color(t logger.LogLevelType) int
- func (f *ApacheCombinedFormatter) EnableForceColors()
- func (f *ApacheCombinedFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *ApacheCombinedFormatter) IsDisableColors() bool
- func (f *ApacheCombinedFormatter) IsForceColors() bool
- func (f *ApacheCombinedFormatter) SetColor(t logger.LogLevelType, reset int)
- func (f *ApacheCombinedFormatter) Sprintf(values ...interface{}) string
- type ApacheCommonFormatter
- func (f *ApacheCommonFormatter) Color(t logger.LogLevelType) int
- func (f *ApacheCommonFormatter) EnableForceColors()
- func (f *ApacheCommonFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *ApacheCommonFormatter) IsDisableColors() bool
- func (f *ApacheCommonFormatter) IsForceColors() bool
- func (f *ApacheCommonFormatter) SetColor(t logger.LogLevelType, reset int)
- func (f *ApacheCommonFormatter) Sprintf(values ...interface{}) string
- type ApacheErrorLogFormatter
- func (f *ApacheErrorLogFormatter) Color(t logger.LogLevelType) int
- func (f *ApacheErrorLogFormatter) EnableForceColors()
- func (f *ApacheErrorLogFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *ApacheErrorLogFormatter) IsDisableColors() bool
- func (f *ApacheErrorLogFormatter) IsForceColors() bool
- func (f *ApacheErrorLogFormatter) SetColor(t logger.LogLevelType, reset int)
- func (f *ApacheErrorLogFormatter) Sprintf(values ...interface{}) string
- type CommonLogFileFormatter
- func (f *CommonLogFileFormatter) Color(t logger.LogLevelType) int
- func (f *CommonLogFileFormatter) EnableForceColors()
- func (f *CommonLogFileFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *CommonLogFileFormatter) IsDisableColors() bool
- func (f *CommonLogFileFormatter) IsForceColors() bool
- func (f *CommonLogFileFormatter) SetColor(t logger.LogLevelType, reset int)
- func (f *CommonLogFileFormatter) Sprintf(values ...interface{}) string
- type CustomFormatterI
- type CustomHandlers
- type RFC3164Formatter
- func (f *RFC3164Formatter) Color(t logger.LogLevelType) int
- func (f *RFC3164Formatter) EnableForceColors()
- func (f *RFC3164Formatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *RFC3164Formatter) IsDisableColors() bool
- func (f *RFC3164Formatter) IsForceColors() bool
- func (f *RFC3164Formatter) SetColor(t logger.LogLevelType, reset int)
- func (f *RFC3164Formatter) Sprintf(values ...interface{}) string
- type RFC5424Formatter
- func (f *RFC5424Formatter) Color(t logger.LogLevelType) int
- func (f *RFC5424Formatter) EnableForceColors()
- func (f *RFC5424Formatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *RFC5424Formatter) IsDisableColors() bool
- func (f *RFC5424Formatter) IsForceColors() bool
- func (f *RFC5424Formatter) SetColor(t logger.LogLevelType, reset int)
- func (f *RFC5424Formatter) Sprintf(values ...interface{}) string
- type TextFormatter
- func (f *TextFormatter) Color(t logger.LogLevelType) int
- func (f *TextFormatter) EnableForceColors()
- func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *TextFormatter) IsDisableColors() bool
- func (f *TextFormatter) IsForceColors() bool
- func (f *TextFormatter) SetColor(t logger.LogLevelType, reset int)
- func (f *TextFormatter) Sprintf(values ...interface{}) string
Constants ¶
const ( AnsiReset = 0 AnsiRed = 31 AnsiHiRed = 91 AnsiGreen = 32 AnsiHiGreen = 92 AnsiYellow = 33 AnsiHiYellow = 93 AnsiBlue = 34 AnsiHiBlue = 94 AnsiMagenta = 35 AnsiHiMagenta = 95 AnsiCyan = 36 AnsiHiCyan = 96 AnsiWhite = 37 AnsiHiWhite = 97 )
ANSI color codes.
const ( // CommonLogFileFormatTemplate : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} HTTP/1.0" {response-code} {bytes} CommonFileFormatTemplate = "%[host]s - %[user]s %[authUserId]d [%[ASC_TIME]s] \"%[method]s %[request]s HTTP/1.0\" %[responseCode]d %[bytes]d" // message template just logs the message. CommonFileFormatMessageTemplate = "%[MESSAGE]s\n" // Detailed template logs padded columns including the running PID. CommonFileFormatDetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. CommonFileFormatDefaultTimestampFormat = "2006-01-02 15:04:05.000" )
const ( // RFC3164LogTemplate : <priority>{timestamp} {hostname} {application}[{pid}]: {message} RFC3164LogTemplate = "<%-7[LEVEL_NAME]s>%[ASC_TIME]s %[hostname]s %[application]s[%-5[process]d]: %[MESSAGE]s" // message template just logs the message. RFC3164MessageTemplate = "%[MESSAGE]s\n" // Detailed template logs padded columns including the running PID. RFC3164DetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. RFC3164DefaultTimestampFormat = "2006-01-02 15:04:05.000" )
const ( // RFC5424LogTemplate : <priority>{version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message} RFC5424LogTemplate = "<priority>{version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message}" // message template just logs the message. RFC5424MessageTemplate = "%[MESSAGE]s\n" // Detailed template logs padded columns including the running PID. RFC5424DetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. RFC5424DefaultTimestampFormat = "2006-01-02 15:04:05.000" )
const ( ASC_TIME string = "ascTime" FIELDS string = "fields" LEVEL_NAME string = "levelName" NAME string = "name" MESSAGE string = "message" PROCESS_PID string = "processPID" RELATIVE_CREATED string = "relativeCreated" SHORT_LEVEL_NAME string = "shortLevelName" HOST string = "host" USER string = "user" AUTH_USER_ID string = "authUserId" METHOD string = "method" REQUEST string = "request" RESPONSE_CODE string = "responseCode" BYTES string = "bytes" REF_ERRER string = "referrer" AGENT string = "agent" USER_IDENTIFIER string = "userIdentifier" DATETIME string = "datetime" TIMESTAMP string = "timestamp" MODULE string = "module" SEVERITY string = "severity" THREAD_ID string = "threadID" CLIENT string = "client" )
Variables ¶
var ( // Basic template just logs the level name, name field, message and fields. // ApacheCombinedFormatTemplate = "%[host]s - %[user]s %[authUserId]d [%[ASC_TIME]s] \"%[method]s %[request]s HTTP/1.0\" %[responseCode]d %[bytes]d \"%[referrer]s\" \"%[agent]s\"" ApacheCombinedFormatTemplate = fmt.Sprintf("%s[%s]s - %s[%s]s %s[%s]d [%s[%s]s] \"%s[%s]s %s[%s]s HTTP/1.0\" %s[%s]d %s[%s]d \"%s[%s]s\" \"%s[%s]s\"\n", "%", HOST, "%", USER, "%", AUTH_USER_ID, "%", ASC_TIME, "%", METHOD, "%", REQUEST, "%", RESPONSE_CODE, "%", BYTES, "%", REF_ERRER, "%", AGENT) // message template just logs the message. ApacheCombinedMessageTemplate = fmt.Sprintf("%s[%s]s\n", "%", MESSAGE) // Detailed template logs padded columns including the running PID. ApacheCombinedDetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[message]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. ApacheCombinedDefaultTimestampFormat = "2006-01-02 15:04:05.000" )
var ( // Basic template just logs the level name, name field, message and fields. // ApacheCommonFormatTemplate : {host} {userIdentifier} {authUserId} [{datetime}] "{method} {request} HTTP/1.0" {responseCode} {bytes} ApacheCommonFormatTemplate = fmt.Sprintf("%s[%s]s - %s[%s]s %s[%s]d [%s[%s]s] \"%s[%s]s %s[%s]s HTTP/1.0\" %s[%s]d %s[%s]d\n", "%", HOST, "%", USER_IDENTIFIER, "%", AUTH_USER_ID, "%", DATETIME, "%", METHOD, "%", REQUEST, "%", RESPONSE_CODE, "%", BYTES) // message template just logs the message. ApacheCommonMessageTemplate = fmt.Sprintf("%s[%s]s\n", "%", MESSAGE) // Detailed template logs padded columns including the running PID. ApacheCommonDetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. ApacheCommonDefaultTimestampFormat = "2006-01-02 15:04:05.000" )
var ( // ApacheErrorFormatTemplate : [{timestamp}] [{module}:{severity}] [pid {pid}:tid {threadID}] [client: %{client}] %{message} ApacheErrorFormatTemplate = fmt.Sprintf("[{%s}] [{%s}:{%s}] [pid {%s}:tid {%s}] [client: %s[%s]s] %s[%s]s\n", TIMESTAMP, MODULE, SEVERITY, PROCESS_PID, THREAD_ID, "%", CLIENT, "%", MESSAGE) // message template just logs the message. ApacheErrorMessageTemplate = fmt.Sprintf("%s[%s]s\n", "%", MESSAGE) // Detailed template logs padded columns including the running PID. ApacheErrorDetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. ApacheErrorDefaultTimestampFormat = "2006-01-02 15:04:05.000" )
var ( // Text log template just logs the level name, name field, message and fields. // TextLogTemplate = "%[levelName]s:%[name]s:%[message]s%[fields]s\n" TextLogTemplate = fmt.Sprintf("%s[%s]s:%s[%s]s:%s[%s]s:%s[%s]s\n", "%", LEVEL_NAME, "%", NAME, "%", MESSAGE, "%", FIELDS) // message template just logs the message. TextMessageTemplate = fmt.Sprintf("%s[%s]s\n", "%", PROCESS_PID) // Detailed template logs padded columns including the running PID. TestDetailedTemplate = "%[ASC_TIME]s %-5[process]d %-7[LEVEL_NAME]s %-20[NAME]s %[MESSAGE]s%[FIELDS]s\n" // defaultTimestampFormat is the default format used if the user does not specify their own. TextDefaultTimestampFormat = "2006-01-02 15:04:05.000" )
Functions ¶
func CallerName ¶
CallerName returns the name of the calling function using the runtime package. Empty string if something fails.
:param skip: Skip these many calls in the stack.
func Color ¶
func Color(entry *logrus.Entry, formatter CustomFormatterI, s string) string
Color colorizes the input string and returns it with ANSI color codes.
func NewLoggerRFC3164Default ¶
func NewLoggerRFC5424Default ¶
func WindowsEnableNativeANSI ¶
WindowsEnableNativeANSI will attempt to set ENABLE_VIRTUAL_TERMINAL_PROCESSING on a console using SetConsoleMode.
:param stdErr: Issue SetConsoleMode win32 api call on stderr instead of stdout handle.
func WindowsNativeANSI ¶
func WindowsNativeANSI() bool
WindowsNativeANSI returns true if either the stderr or stdout consoles natively support ANSI color codes. On non-Windows platforms this always returns false.
Types ¶
type ApacheCombinedFormatter ¶
type ApacheCombinedFormatter struct {
// contains filtered or unexported fields
}
func (*ApacheCombinedFormatter) Color ¶
func (f *ApacheCombinedFormatter) Color(t logger.LogLevelType) int
func (*ApacheCombinedFormatter) EnableForceColors ¶
func (f *ApacheCombinedFormatter) EnableForceColors()
func (*ApacheCombinedFormatter) Format ¶
format is called by logrus and returns the formatted string.
func (*ApacheCombinedFormatter) IsDisableColors ¶
func (f *ApacheCombinedFormatter) IsDisableColors() bool
func (*ApacheCombinedFormatter) IsForceColors ¶
func (f *ApacheCombinedFormatter) IsForceColors() bool
func (*ApacheCombinedFormatter) SetColor ¶
func (f *ApacheCombinedFormatter) SetColor(t logger.LogLevelType, reset int)
type ApacheCommonFormatter ¶
type ApacheCommonFormatter struct {
// contains filtered or unexported fields
}
func (*ApacheCommonFormatter) Color ¶
func (f *ApacheCommonFormatter) Color(t logger.LogLevelType) int
func (*ApacheCommonFormatter) EnableForceColors ¶
func (f *ApacheCommonFormatter) EnableForceColors()
func (*ApacheCommonFormatter) IsDisableColors ¶
func (f *ApacheCommonFormatter) IsDisableColors() bool
func (*ApacheCommonFormatter) IsForceColors ¶
func (f *ApacheCommonFormatter) IsForceColors() bool
func (*ApacheCommonFormatter) SetColor ¶
func (f *ApacheCommonFormatter) SetColor(t logger.LogLevelType, reset int)
type ApacheErrorLogFormatter ¶
type ApacheErrorLogFormatter struct {
// contains filtered or unexported fields
}
func (*ApacheErrorLogFormatter) Color ¶
func (f *ApacheErrorLogFormatter) Color(t logger.LogLevelType) int
func (*ApacheErrorLogFormatter) EnableForceColors ¶
func (f *ApacheErrorLogFormatter) EnableForceColors()
func (*ApacheErrorLogFormatter) Format ¶
format is called by logrus and returns the formatted string.
func (*ApacheErrorLogFormatter) IsDisableColors ¶
func (f *ApacheErrorLogFormatter) IsDisableColors() bool
func (*ApacheErrorLogFormatter) IsForceColors ¶
func (f *ApacheErrorLogFormatter) IsForceColors() bool
func (*ApacheErrorLogFormatter) SetColor ¶
func (f *ApacheErrorLogFormatter) SetColor(t logger.LogLevelType, reset int)
type CommonLogFileFormatter ¶
type CommonLogFileFormatter struct {
// contains filtered or unexported fields
}
func (*CommonLogFileFormatter) Color ¶
func (f *CommonLogFileFormatter) Color(t logger.LogLevelType) int
func (*CommonLogFileFormatter) EnableForceColors ¶
func (f *CommonLogFileFormatter) EnableForceColors()
func (*CommonLogFileFormatter) Format ¶
format is called by logrus and returns the formatted string.
func (*CommonLogFileFormatter) IsDisableColors ¶
func (f *CommonLogFileFormatter) IsDisableColors() bool
func (*CommonLogFileFormatter) IsForceColors ¶
func (f *CommonLogFileFormatter) IsForceColors() bool
func (*CommonLogFileFormatter) SetColor ¶
func (f *CommonLogFileFormatter) SetColor(t logger.LogLevelType, reset int)
type CustomFormatterI ¶
type CustomFormatterI interface { Format(entry *logrus.Entry) ([]byte, error) Sprintf(values ...interface{}) string EnableForceColors() IsForceColors() bool IsDisableColors() bool Color(t logger.LogLevelType) int SetColor(t logger.LogLevelType, reset int) // contains filtered or unexported methods }
func NewFormatter ¶
func NewFormatter(template string, custom CustomHandlers) CustomFormatterI
NewFormatter creates a new customFormatter, sets the template string, and returns its pointer. This function is usually called just once during a running program's lifetime.
:param template: Pre-processed formatting template (e.g. "%[message]s\n").
:param custom: User-defined formatters evaluated before built-in formatters. Keys are attributes to look for in the
formatting string (e.g. "%[myFormatter]s") and values are formatting functions.
type CustomHandlers ¶
type CustomHandlers map[string]handler
CustomHandlers is a mapping of handler-type functions to attributes as key names (e.g. "levelName").
With this type many custom handler functions can be defined and fed to NewFormatter(). CustomHandlers are parsed first so you can override built-in handlers such as the one for %[ASC_TIME]s with your own. Since they are exported you can call built-in handlers in your own custom handler. The returned interface{} value is passed to fmt.Sprintf().
In addition to overriding handlers you can create new attributes (such as %[myAttr]s) and map it to your handler function.
type RFC3164Formatter ¶
type RFC3164Formatter struct {
// contains filtered or unexported fields
}
func (*RFC3164Formatter) Color ¶
func (f *RFC3164Formatter) Color(t logger.LogLevelType) int
func (*RFC3164Formatter) EnableForceColors ¶
func (f *RFC3164Formatter) EnableForceColors()
func (*RFC3164Formatter) IsDisableColors ¶
func (f *RFC3164Formatter) IsDisableColors() bool
func (*RFC3164Formatter) IsForceColors ¶
func (f *RFC3164Formatter) IsForceColors() bool
func (*RFC3164Formatter) SetColor ¶
func (f *RFC3164Formatter) SetColor(t logger.LogLevelType, reset int)
type RFC5424Formatter ¶
type RFC5424Formatter struct {
// contains filtered or unexported fields
}
func (*RFC5424Formatter) Color ¶
func (f *RFC5424Formatter) Color(t logger.LogLevelType) int
func (*RFC5424Formatter) EnableForceColors ¶
func (f *RFC5424Formatter) EnableForceColors()
func (*RFC5424Formatter) IsDisableColors ¶
func (f *RFC5424Formatter) IsDisableColors() bool
func (*RFC5424Formatter) IsForceColors ¶
func (f *RFC5424Formatter) IsForceColors() bool
func (*RFC5424Formatter) SetColor ¶
func (f *RFC5424Formatter) SetColor(t logger.LogLevelType, reset int)
type TextFormatter ¶
type TextFormatter struct {
// contains filtered or unexported fields
}
func (*TextFormatter) Color ¶
func (f *TextFormatter) Color(t logger.LogLevelType) int
func (*TextFormatter) EnableForceColors ¶
func (f *TextFormatter) EnableForceColors()
func (*TextFormatter) IsDisableColors ¶
func (f *TextFormatter) IsDisableColors() bool
func (*TextFormatter) IsForceColors ¶
func (f *TextFormatter) IsForceColors() bool
func (*TextFormatter) SetColor ¶
func (f *TextFormatter) SetColor(t logger.LogLevelType, reset int)