log

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 11 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileWriter added in v0.4.0

func NewFileWriter(path string) (io.WriteCloser, error)

NewFileWriter returns a writer that writes to the specified file.

func NewRotatorWriter added in v0.4.0

func NewRotatorWriter(path string, maxSize int64, maxFiles int) (io.WriteCloser, error)

NewRotatorWriter returns a writer that writes to the specified file and rotates the file (zips the log to a numbered gz file and creates a new uncompressed log file) when the specified size is reached. If maxFiles is zero, the log is not rotated. Be sure to Close the returned writer.

Types

type Format added in v0.4.0

type Format string
const (
	FormatText         Format = "text"
	FormatJSON         Format = "json"
	FormatUnstructured Format = "plain"
)

func ParseFormat added in v0.4.0

func ParseFormat(format string) (Format, error)

type KVLogger added in v0.4.0

type KVLogger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	Log(level Level, msg string, args ...any)
}

type LazyHex added in v0.4.0

type LazyHex []byte

LazyHex is a helper type for when logging a byte slice as a hexadecimal string, but only when it is actually printed. For example, in a debug log that may not be printed unless the logging level is set to debug. Note that in printf style logging with %x this is not an issue, but with the pervasive trend of providing key value pairs, this is not possible.

func (LazyHex) String added in v0.4.0

func (lh LazyHex) String() string

type Level

type Level int
const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

func ParseLevel added in v0.2.0

func ParseLevel(s string) (Level, error)

ParseLevel parses a string into a log level. Use Level.String to go from a Level to a string.

func (Level) MarshalText added in v0.4.0

func (lvl Level) MarshalText() (text []byte, err error)

func (Level) String added in v0.4.0

func (lvl Level) String() string

String returns the string representation of the log level. Use ParseLevel to go from a string to a Level.

func (*Level) UnmarshalText added in v0.4.0

func (lvl *Level) UnmarshalText(text []byte) error

type Logger

type Logger interface {
	KVLogger // (msg string, args ...any) where args are key-value pairs
	Loggerf  // (msg string, args ...any) where args are printf like arguments
	Loggerln // (a ...any) in the manner of println

	LoggerMaker
}
var DiscardLogger Logger = &discardLogger{} // New(WithWriter(io.Discard))

func New

func New(opts ...Option) Logger

func NewStdoutLogger added in v0.4.0

func NewStdoutLogger() Logger

type LoggerMaker added in v0.4.0

type LoggerMaker interface {
	// New creates a child logger using the same backend and options as the
	// current logger, but with the specified name and level.
	New(name string) Logger
	NewWithLevel(lvl Level, name string) Logger
}

type Loggerf added in v0.4.0

type Loggerf interface {
	Debugf(msg string, args ...any)
	Infof(msg string, args ...any)
	Warnf(msg string, args ...any)
	Errorf(msg string, args ...any)
	Logf(level Level, msg string, args ...any)
}

type Loggerln added in v0.4.0

type Loggerln interface {
	Debugln(a ...any)
	Infoln(a ...any)
	Warnln(a ...any)
	Errorln(a ...any)
	Logln(level Level, a ...any)
}

type Option added in v0.4.0

type Option func(*options)

func WithFormat added in v0.4.0

func WithFormat(format Format) Option

func WithLevel added in v0.4.0

func WithLevel(level Level) Option

func WithName added in v0.4.0

func WithName(name string) Option

func WithSource added in v0.4.0

func WithSource(enabled bool) Option

func WithWriter added in v0.4.0

func WithWriter(w io.Writer) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳