formatter

package
v0.0.0-...-1d97044 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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"
)
View Source
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"
)
View Source
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"
)
View Source
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

View Source
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"
)
View Source
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"
)
View Source
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"
)
View Source
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

func CallerName(skip int) string

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 NewApacheCommonLogFormatterDefault

func NewApacheCommonLogFormatterDefault() *loggerAVA.Logger

func NewLoggerApacheCombinedLogFormatterDefault

func NewLoggerApacheCombinedLogFormatterDefault() *loggerAVA.Logger

func NewLoggerApacheErrorLogFormatterDefault

func NewLoggerApacheErrorLogFormatterDefault() *loggerAVA.Logger

func NewLoggerCommonLogfileFormatterDefault

func NewLoggerCommonLogfileFormatterDefault() *loggerAVA.Logger

func NewLoggerRFC3164Default

func NewLoggerRFC3164Default() *loggerAVA.Logger

func NewLoggerRFC5424Default

func NewLoggerRFC5424Default() *loggerAVA.Logger

func NewLoggerTextFormatterDefault

func NewLoggerTextFormatterDefault() *loggerAVA.Logger

func WindowsEnableNativeANSI

func WindowsEnableNativeANSI(stderr bool) *errorAVA.Error

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

func (f *ApacheCombinedFormatter) Format(entry *logrus.Entry) ([]byte, error)

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)

func (*ApacheCombinedFormatter) Sprintf

func (f *ApacheCombinedFormatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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) Format

func (f *ApacheCommonFormatter) Format(entry *logrus.Entry) ([]byte, error)

format is called by logrus and returns the formatted string.

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)

func (*ApacheCommonFormatter) Sprintf

func (f *ApacheCommonFormatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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

func (f *ApacheErrorLogFormatter) Format(entry *logrus.Entry) ([]byte, error)

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)

func (*ApacheErrorLogFormatter) Sprintf

func (f *ApacheErrorLogFormatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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

func (f *CommonLogFileFormatter) Format(entry *logrus.Entry) ([]byte, error)

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)

func (*CommonLogFileFormatter) Sprintf

func (f *CommonLogFileFormatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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) Format

func (f *RFC3164Formatter) Format(entry *logrus.Entry) ([]byte, error)

format is called by logrus and returns the formatted string.

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)

func (*RFC3164Formatter) Sprintf

func (f *RFC3164Formatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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) Format

func (f *RFC5424Formatter) Format(entry *logrus.Entry) ([]byte, error)

format is called by logrus and returns the formatted string.

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)

func (*RFC5424Formatter) Sprintf

func (f *RFC5424Formatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

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) Format

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

format is called by logrus and returns the formatted string.

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)

func (*TextFormatter) Sprintf

func (f *TextFormatter) Sprintf(values ...interface{}) string

Sprintf is like fmt.Sprintf() but exclude ANSI color sequences from string padding.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL