lumberjack

package module
v0.0.0-...-b87209e Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package lumberjack provides the slog handler.

Index

Constants

View Source
const (
	// DefaultFormat is the default format for lumberjack.
	DefaultFormat = "json"
)
View Source
const Name = "lumberjack"

Name is this providers name.

Variables

This section is empty.

Functions

func Factory

func Factory(sections []string, configs types.ConfigData, opts ...log.Option) (log.ProviderType, error)

Factory is the factory for a slog provider.

func WithCompress

func WithCompress(n bool) log.Option

WithCompress determines if the rotated log files should be compressed using gzip. The default is not to perform compression.

func WithFile

func WithFile(n string) log.Option

WithFile sets the target for the logger, available options: os.Stdout, os.Stderr, /somedir/somefile.

func WithFormat

func WithFormat(n string) log.Option

WithFormat sets the format for the logger.

func WithLocalTime

func WithLocalTime(n bool) log.Option

WithLocalTime determines if the time used for formatting the timestamps in backup files is the computer's local time. The default is to use UTC time.

func WithMaxAge

func WithMaxAge(n int) log.Option

WithMaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. Note that a day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc. The default is not to remove old log files based on age.

func WithMaxBackups

func WithMaxBackups(n int) log.Option

WithMaxBackups is the maximum number of old log files to retain. The default is to retain all old log files (though MaxAge may still cause them to get deleted.)

func WithMaxSize

func WithMaxSize(n int) log.Option

WithMaxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 100 megabytes.

Types

type Config

type Config struct {
	log.Config

	// Format is the log format, either json or text.
	Format string `json:"format" yaml:"format"`
	// File is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	File string `json:"file" yaml:"file"`

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `json:"maxSize" yaml:"maxSize"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `json:"maxBackups" yaml:"maxBackups"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `json:"maxAge" yaml:"maxAge"`

	// LocalTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool `json:"localTime" yaml:"localTime"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `json:"compress" yaml:"compress"`
}

Config is the config struct for slog.

func NewConfig

func NewConfig(section []string, configs types.ConfigData, opts ...log.Option) (Config, error)

NewConfig creates a new config.

type Provider

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

Provider is the provider for slog.

func (*Provider) Handler

func (p *Provider) Handler() (slog.Handler, error)

Handler returns the configure handler.

func (*Provider) Key

func (p *Provider) Key() string

Key returns an identifier for this handler provider with its config.

func (*Provider) Start

func (p *Provider) Start() error

Start configures the slog Handler.

func (*Provider) Stop

func (p *Provider) Stop(_ context.Context) error

Stop closes if required a open log file.

Jump to

Keyboard shortcuts

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