log

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormatType = fmt.Errorf("not a valid FormatType, try [%s]", strings.Join(_FormatTypeNames, ", "))
View Source
var ErrInvalidSyslogFacility = fmt.Errorf("not a valid SyslogFacility, try [%s]", strings.Join(_SyslogFacilityNames, ", "))
View Source
var ErrInvalidTargetType = fmt.Errorf("not a valid TargetType, try [%s]", strings.Join(_TargetTypeNames, ", "))

Functions

func Configure

func Configure(cfg *Config)

Configure applies configuration to the global logger.

func ConfigureLogger

func ConfigureLogger(logger *logrus.Logger, cfg *Config)

Configure applies configuration to the given logger.

func CtxWithFields

func CtxWithFields(ctx context.Context, fields logrus.Fields) (context.Context, *logrus.Entry)

func EscapeInput

func EscapeInput(input string) string

EscapeInput removes line breaks from input

func FormatTypeNames

func FormatTypeNames() []string

FormatTypeNames returns a list of possible string values of FormatType.

func FromCtx

func FromCtx(ctx context.Context) *logrus.Entry

func Log

func Log() *logrus.Logger

Log returns the global logger

func NewCtx

func NewCtx(ctx context.Context, logger *logrus.Entry) (context.Context, *logrus.Entry)

func PrefixedLog

func PrefixedLog(prefix string) *logrus.Entry

PrefixedLog return the global logger with prefix

func SetPrefix added in v0.33.0

func SetPrefix(logger *logrus.Entry, prefix string) *logrus.Entry

SetPrefix sets prefix as the logger's prefix, replacing any prefix it already carries. Use this to give each resolver its own prefix without accumulating the prefixes of resolvers earlier in the chain. Contrast with WithPrefix, which appends to build a dotted chain (a.b.c).

func Silence

func Silence()

Silence disables the logger output

func SyslogFacilityNames added in v0.36.0

func SyslogFacilityNames() []string

SyslogFacilityNames returns a list of possible string values of SyslogFacility.

func TargetTypeNames added in v0.36.0

func TargetTypeNames() []string

TargetTypeNames returns a list of possible string values of TargetType.

func WithIndent

func WithIndent(log *logrus.Entry, prefix string, callback func(*logrus.Entry))

func WithPrefix

func WithPrefix(logger *logrus.Entry, prefix string) *logrus.Entry

WithPrefix adds the given prefix to the logger.

func WrapCtx

func WrapCtx(ctx context.Context, wrap func(*logrus.Entry) *logrus.Entry) (context.Context, *logrus.Entry)

WrapCtx derives a new context logger by applying `wrap` to the context-stored entry.

`wrap` MUST return a new entry (e.g. via WithField/WithFields) and MUST NOT mutate the entry it is given in place: the base entry is passed without copying (the wrapped result is a fresh entry and NewCtx re-stamps its Context), so an in-place mutation would corrupt the shared context-stored logger.

Types

type Buffer added in v0.36.0

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

Buffer holds what is logged to its entry, at any level, until Replay logs it to another logger. What is logged before that logger is set up still follows its level, format and target.

func NewBuffer added in v0.36.0

func NewBuffer() *Buffer

NewBuffer returns an empty Buffer.

func (*Buffer) Entry added in v0.36.0

func (b *Buffer) Entry() *logrus.Entry

Entry returns an entry logging to the buffer.

func (*Buffer) Fire added in v0.36.0

func (b *Buffer) Fire(entry *logrus.Entry) error

Fire implements `logrus.Hook`.

func (*Buffer) Levels added in v0.36.0

func (b *Buffer) Levels() []logrus.Level

Levels implements `logrus.Hook`.

func (*Buffer) Replay added in v0.36.0

func (b *Buffer) Replay(logger *logrus.Logger)

Replay logs the held entries to logger, as far as its level allows, and empties the buffer.

type Config

type Config struct {
	Level     logrus.Level `default:"info"   yaml:"level"`
	Format    FormatType   `default:"text"   yaml:"format"`
	Target    TargetType   `default:"stdout" yaml:"target"`
	Syslog    SyslogConfig `yaml:"syslog"`
	Privacy   bool         `default:"false"  yaml:"privacy"`
	Timestamp bool         `default:"true"   yaml:"timestamp"`
}

Config defines all logging configurations

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a new Config initialized with default values.

type FormatType

type FormatType int

FormatType format for logging ENUM( text // Human-readable text. json // Structured JSON. )

const (
	// FormatTypeText is a FormatType of type Text.
	// Human-readable text.
	FormatTypeText FormatType = iota
	// FormatTypeJson is a FormatType of type Json.
	// Structured JSON.
	FormatTypeJson
)

func ParseFormatType

func ParseFormatType(name string) (FormatType, error)

ParseFormatType attempts to convert a string to a FormatType.

func (*FormatType) AppendText added in v0.28.0

func (x *FormatType) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (FormatType) EnumDescriptions added in v0.31.0

func (FormatType) EnumDescriptions() map[string]string

EnumDescriptions returns each enum value's description, taken from the `// comment` in the ENUM(...) declaration. Generated; do not edit.

func (FormatType) EnumValues added in v0.31.0

func (FormatType) EnumValues() []string

EnumValues returns the enum's accepted string values, used to build the JSON schema enum constraint. Generated; do not edit.

func (FormatType) IsValid

func (x FormatType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (FormatType) MarshalText

func (x FormatType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (FormatType) String

func (x FormatType) String() string

String implements the Stringer interface.

func (*FormatType) UnmarshalText

func (x *FormatType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type MockLoggerHook

type MockLoggerHook struct {
	mock.Mock

	Messages []string
	// contains filtered or unexported fields
}

func NewMockEntry

func NewMockEntry() (*logrus.Entry, *MockLoggerHook)

func (*MockLoggerHook) Fire

func (h *MockLoggerHook) Fire(entry *logrus.Entry) error

Fire implements `logrus.Hook`.

func (*MockLoggerHook) Levels

func (h *MockLoggerHook) Levels() []logrus.Level

Levels implements `logrus.Hook`.

func (*MockLoggerHook) Reset added in v0.28.0

func (h *MockLoggerHook) Reset()

Reset clears the Messages slice, removing all logged messages. It is safe to call concurrently with other methods on MockLoggerHook, as all access to Messages is protected by a mutex.

type SyslogConfig added in v0.36.0

type SyslogConfig struct {
	// Network is empty for the local syslog socket, otherwise "udp" or "tcp"
	Network  string         `default:""       yaml:"network"`
	Address  string         `default:""       yaml:"address"`
	Tag      string         `default:"blocky" yaml:"tag"`
	Facility SyslogFacility `default:"daemon" yaml:"facility"`
}

SyslogConfig defines where and as what blocky logs when the target is syslog

type SyslogFacility added in v0.36.0

type SyslogFacility string

SyslogFacility is the facility used for syslog messages. ENUM( daemon // System daemon messages. user // User-level messages. local0 // Local use facility 0. local1 // Local use facility 1. local2 // Local use facility 2. local3 // Local use facility 3. local4 // Local use facility 4. local5 // Local use facility 5. local6 // Local use facility 6. local7 // Local use facility 7. )

const (
	// SyslogFacilityDaemon is a SyslogFacility of type daemon.
	// System daemon messages.
	SyslogFacilityDaemon SyslogFacility = "daemon"
	// SyslogFacilityUser is a SyslogFacility of type user.
	// User-level messages.
	SyslogFacilityUser SyslogFacility = "user"
	// SyslogFacilityLocal0 is a SyslogFacility of type local0.
	// Local use facility 0.
	SyslogFacilityLocal0 SyslogFacility = "local0"
	// SyslogFacilityLocal1 is a SyslogFacility of type local1.
	// Local use facility 1.
	SyslogFacilityLocal1 SyslogFacility = "local1"
	// SyslogFacilityLocal2 is a SyslogFacility of type local2.
	// Local use facility 2.
	SyslogFacilityLocal2 SyslogFacility = "local2"
	// SyslogFacilityLocal3 is a SyslogFacility of type local3.
	// Local use facility 3.
	SyslogFacilityLocal3 SyslogFacility = "local3"
	// SyslogFacilityLocal4 is a SyslogFacility of type local4.
	// Local use facility 4.
	SyslogFacilityLocal4 SyslogFacility = "local4"
	// SyslogFacilityLocal5 is a SyslogFacility of type local5.
	// Local use facility 5.
	SyslogFacilityLocal5 SyslogFacility = "local5"
	// SyslogFacilityLocal6 is a SyslogFacility of type local6.
	// Local use facility 6.
	SyslogFacilityLocal6 SyslogFacility = "local6"
	// SyslogFacilityLocal7 is a SyslogFacility of type local7.
	// Local use facility 7.
	SyslogFacilityLocal7 SyslogFacility = "local7"
)

func ParseSyslogFacility added in v0.36.0

func ParseSyslogFacility(name string) (SyslogFacility, error)

ParseSyslogFacility attempts to convert a string to a SyslogFacility.

func (*SyslogFacility) AppendText added in v0.36.0

func (x *SyslogFacility) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (SyslogFacility) EnumDescriptions added in v0.36.0

func (SyslogFacility) EnumDescriptions() map[string]string

EnumDescriptions returns each enum value's description, taken from the `// comment` in the ENUM(...) declaration. Generated; do not edit.

func (SyslogFacility) EnumValues added in v0.36.0

func (SyslogFacility) EnumValues() []string

EnumValues returns the enum's accepted string values, used to build the JSON schema enum constraint. Generated; do not edit.

func (SyslogFacility) IsValid added in v0.36.0

func (x SyslogFacility) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (SyslogFacility) MarshalText added in v0.36.0

func (x SyslogFacility) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (SyslogFacility) String added in v0.36.0

func (x SyslogFacility) String() string

String implements the Stringer interface.

func (*SyslogFacility) UnmarshalText added in v0.36.0

func (x *SyslogFacility) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type TargetType added in v0.36.0

type TargetType int

TargetType destination for logging ENUM( stdout // Standard output. stderr // Standard error. syslog // System log, each entry at the priority matching its level. )

const (
	// TargetTypeStdout is a TargetType of type Stdout.
	// Standard output.
	TargetTypeStdout TargetType = iota
	// TargetTypeStderr is a TargetType of type Stderr.
	// Standard error.
	TargetTypeStderr
	// TargetTypeSyslog is a TargetType of type Syslog.
	// System log, each entry at the priority matching its level.
	TargetTypeSyslog
)

func ParseTargetType added in v0.36.0

func ParseTargetType(name string) (TargetType, error)

ParseTargetType attempts to convert a string to a TargetType.

func (*TargetType) AppendText added in v0.36.0

func (x *TargetType) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (TargetType) EnumDescriptions added in v0.36.0

func (TargetType) EnumDescriptions() map[string]string

EnumDescriptions returns each enum value's description, taken from the `// comment` in the ENUM(...) declaration. Generated; do not edit.

func (TargetType) EnumValues added in v0.36.0

func (TargetType) EnumValues() []string

EnumValues returns the enum's accepted string values, used to build the JSON schema enum constraint. Generated; do not edit.

func (TargetType) IsValid added in v0.36.0

func (x TargetType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (TargetType) MarshalText added in v0.36.0

func (x TargetType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (TargetType) String added in v0.36.0

func (x TargetType) String() string

String implements the Stringer interface.

func (*TargetType) UnmarshalText added in v0.36.0

func (x *TargetType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

Jump to

Keyboard shortcuts

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