dflog

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLogTimeFormat = "2006-01-02 15:04:05.000"

DefaultLogTimeFormat defines the timestamp format.

Variables

This section is empty.

Functions

func Init added in v1.0.0

func Init(l *logrus.Logger, opts ...Option) error

Init initializes the logger with given options. If no option is provided, the logger's formatter will be set with an empty sign.

Types

type ConsoleHook

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

ConsoleHook shows logs on console.

func (*ConsoleHook) Fire

func (ch *ConsoleHook) Fire(entry *logrus.Entry) error

Fire implements Hook#Fire.

func (*ConsoleHook) Levels

func (ch *ConsoleHook) Levels() []logrus.Level

Levels implements Hook#Levels().

type DragonflyFormatter

type DragonflyFormatter struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string
	Sign            string
}

DragonflyFormatter customizes the dragonfly log format.

func (*DragonflyFormatter) Format

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

Format implements Formatter#Format.

type LogConfig added in v1.0.0

type LogConfig struct {
	// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
	// It defaults to 40 megabytes.
	MaxSize int `yaml:"maxSize" json:"maxSize"`
	// MaxBackups is the maximum number of old log files to retain.
	// The default value is 1.
	MaxBackups int `yaml:"maxBackups" json:"maxBackups"`

	// Path is the location of log file
	// The default value is logs/dfdaemon.log
	Path string `yaml:"path" json:"path"`
}

LogConfig holds all configurable properties of log.

type Option added in v1.0.0

type Option func(l *logrus.Logger) error

Option is a functional configuration for the given logrus logger.

func WithConsole added in v1.0.0

func WithConsole() Option

WithConsole adds a hook to output logs to stdout.

func WithDebug added in v1.0.0

func WithDebug(debug bool) Option

WithDebug sets the log level to debug.

func WithLogFile added in v1.0.0

func WithLogFile(f string, maxSize, maxBackups int) Option

WithLogFile sets the logger to output to the given file, with log rotation.

If the given file is empty, nothing will be done.

The maxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 40 megabytes.

The maxBackups is the maximum number of old log files to retain. The default value is 1.

func WithMaxSizeMB added in v1.0.0

func WithMaxSizeMB(max uint) Option

WithMaxSizeMB sets the max size of log files in MB. If the logger is not configured to use a log file, an error is returned.

func WithSign added in v1.0.0

func WithSign(sign string) Option

WithSign sets the sign in formatter.

Jump to

Keyboard shortcuts

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