logger

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FORMATTER_TEXT   = "text"
	FORMATTER_JSON   = "json"
	FORMATTER_LOGFMT = "logfmt"
)

Variables

Functions

func FormatPayload

func FormatPayload(payload []byte, length, cutLength, runesPerLine int) string

func InitLog

func InitLog(level, formatter string, logMethod bool) error

Types

type CompColorMap

type CompColorMap map[string]int

CompColorMap keeps track of color for each component.

type FieldMap

type FieldMap map[string]string

FieldMap allows customization of the key names for default fields.

type Logger

type Logger struct {
	log.FieldLogger
}

func LogWithComponent

func LogWithComponent(comp string) *Logger

func StandardLogger

func StandardLogger() *Logger

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...interface{})

func (*Logger) Traceln

func (l *Logger) Traceln(args ...interface{})

func (*Logger) WithComponent

func (l *Logger) WithComponent(comp string) *Logger

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

func (*Logger) WithField

func (l *Logger) WithField(key string, value interface{}) *Logger

func (*Logger) WithFields

func (l *Logger) WithFields(fields log.Fields) *Logger

type TextFormatter

type TextFormatter struct {
	// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
	EnvironmentOverrideColors bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	// The keys sorting function, when uninitialized it uses sort.Strings.
	SortingFunc func([]string)

	// Disables the truncation of the level text to 4 characters.
	DisableLevelTruncation bool

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool

	// FieldMap allows users to customize the names of keys for default fields.
	// As an example:
	// formatter := &TextFormatter{
	//     FieldMap: FieldMap{
	//         FieldKeyTime:  "@timestamp",
	//         FieldKeyLevel: "@level",
	//         FieldKeyMsg:   "@message"}}
	FieldMap     FieldMap
	ComponentMap FieldMap
	ColorMap     CompColorMap

	// CallerPrettyfier can be set by the user to modify the content
	// of the function and file keys in the data when ReportCaller is
	// activated. If any of the returned value is the empty string the
	// corresponding key will be removed from fields.
	CallerPrettyfier func(*runtime.Frame) (function string, file string)
	// contains filtered or unexported fields
}

TextFormatter formats logs into text

func (*TextFormatter) Format

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

Format renders a single log entry

Jump to

Keyboard shortcuts

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