logging

package
v1.2.9 Latest Latest
Warning

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

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

Documentation

Overview

Package logging contains utilities for logging.

Index

Constants

View Source
const (
	FieldsKey = "fields."
)
View Source
const (
	LogSequence = "log_sequence"
)
View Source
const (
	OpField = "op"
)

Variables

This section is empty.

Functions

func LogLevel

func LogLevel(name string) logrus.Level

func LogToFile

func LogToFile(file string) *logrus.Logger

func NewLogger

func NewLogger() *logrus.Logger

func SetUpLogging

func SetUpLogging(level string, format LogFormat)

Types

type FieldMap

type FieldMap map[fieldKey]string

FieldMap allows customization of the key names for default fields.

type LogFormat

type LogFormat string
const (
	LogFormatJSON         LogFormat = "json"
	LogFormatText         LogFormat = "text"
	LogFormatTextColorful LogFormat = "text:colorful"

	DefaultLogLevel = "info"
)

type PlainTextFormatter

type PlainTextFormatter struct {
	// Force quoting of all values
	ForceQuote bool

	// DisableQuote disables quoting for all values.
	// DisableQuote will have a lower priority than ForceQuote.
	// If both of them are set to true, quote will be forced on all values.
	DisableQuote 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.
	// The format to use is the same than for time.Format or time.Parse from the standard
	// library.
	// The standard Library already provides a set of predefined format.
	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

	// PadLevelText Adds padding the level text so that all the levels output at the same length
	// PadLevelText is a superset of the DisableLevelTruncation option
	PadLevelText 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 := &PlainTextFormatter{
	//     FieldMap: FieldMap{
	//         FieldKeyTime:  "@timestamp",
	//         FieldKeyLevel: "@level",
	//         FieldKeyMsg:   "@message"}}
	FieldMap FieldMap

	// 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
}

PlainTextFormatter formats logs into text

func (*PlainTextFormatter) Format

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

Format renders a single log entry

type SequenceLogger

type SequenceLogger struct {
	// contains filtered or unexported fields
}

SequenceLogger adds a monotonically increasing number to each log entry, to allow ordering when time to the millisecond is identical (a limitation of AWS CloudWatch's @timestamp field). In CloudWatch query, can add a secondary sort key like so:

| sort @timestamp desc, log_sequence desc

func NewSequenceLogger

func NewSequenceLogger(wrap logrus.Formatter) *SequenceLogger

func (*SequenceLogger) Format

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

Jump to

Keyboard shortcuts

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