log

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Filename where the log is stored.
	Filename string `yaml:"filename" mapstructure:"filename"`

	// Directory where the log files are stored.
	Directory string `yaml:"directory" mapstructure:"directory"`

	// Timestamp format when rotation files.
	FileTimestampFormat string `yaml:"file_timestamp_format" mapstructure:"file_timestamp_format"`

	// Maximum filesize, the log is rotated when this size is exceeded.
	MaxFileSize types.Size `yaml:"maxfilesize" mapstructure:"maxfilesize"`

	// Maximum lifetime of the file before it is rotated.
	MaxTime time.Duration `yaml:"maxtime" mapstructure:"maxtime"`
}

Config represents configuration parameters for a log.

func (Config) GetDirectory

func (c Config) GetDirectory() string

func (Config) GetFilePath

func (c Config) GetFilePath() string

func (Config) GetFilename

func (c Config) GetFilename() string

type HookWriter

type HookWriter struct {
	Writer    io.Writer
	LogLevels []log.Level
}

func MakeErrorHook

func MakeErrorHook(writer io.Writer) *HookWriter

func MakeStdHook

func MakeStdHook(writer io.Writer) *HookWriter

func (*HookWriter) Fire

func (hook *HookWriter) Fire(entry *log.Entry) error

func (*HookWriter) Levels

func (hook *HookWriter) Levels() []log.Level

type RotatingFile

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

Rotating file represents a file that can be rotated when either the file becomes to large or to old, whatever comes first

func NewRotatingFile

func NewRotatingFile(filename string, opts ...RotatingFileOption) (*RotatingFile, error)

Open a new rotating file.

func NewRotatingFileFromConfig

func NewRotatingFileFromConfig(config Config, suffix string) (*RotatingFile, error)

Open a new rotating file using a config struct.

func (*RotatingFile) Close

func (w *RotatingFile) Close() error

Implement io.Closer interface

func (RotatingFile) GetFilename

func (w RotatingFile) GetFilename() string

Get the filename

func (*RotatingFile) Rotate

func (w *RotatingFile) Rotate() error

Rotate the file.

func (*RotatingFile) Write

func (w *RotatingFile) Write(p []byte) (int, error)

Implement io.Writer interface

type RotatingFileOption

type RotatingFileOption func(*RotatingFile)

func WithMaxAge

func WithMaxAge(value time.Duration) RotatingFileOption

func WithMaxSize

func WithMaxSize(value int64) RotatingFileOption

func WithTimestampFormat

func WithTimestampFormat(value string) RotatingFileOption

Jump to

Keyboard shortcuts

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