logging

package
v0.0.0-...-6d02989 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	File   = "file"
	Stdout = "stdout"
	Stderr = "stderr"
)

Log writers.

View Source
const (
	JSON = "json"
	Text = "text"
)

Log formatters.

Variables

View Source
var (
	// ErrInvalidWriterType is returned when a writer has an invalid type.
	ErrInvalidWriterType = errors.New("log writer has an invalid type")

	// ErrInvalidWriterLevel is returned when a writer has an invalid
	// level.
	ErrInvalidWriterLevel = errors.New("log writer has an invalid level")

	// ErrInvalidWriterFormatter is returned when a writer has an invalid
	// formatter.
	ErrInvalidWriterFormatter = errors.New("log writer has an invalid formatter")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Writers are the writers for the log.
	Writers []WriterConfig `toml:"writers"`
}

Config contains configuration options for the log.

type ConfigHandler

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

ConfigHandler is the handler of the log configuration.

func (*ConfigHandler) Config

func (h *ConfigHandler) Config() interface{}

Config returns the current service configuration or creates one with good default values.

The default configuration writes to a single file using the JSON formatter and weekly rotations.

func (*ConfigHandler) ID

func (h *ConfigHandler) ID() string

ID returns the unique identifier of the configuration.

func (*ConfigHandler) SetConfig

func (h *ConfigHandler) SetConfig(config interface{}) error

SetConfig configures the service handler.

type WriterConfig

type WriterConfig struct {
	// Type is the type of the writer.
	Type string `toml:"type" comment:"The type of writer (file, stdout, stderr)."`

	// Level is the log level for the writer.
	Level string `toml:"level" comment:"The log level for the writer (trace, debug, info, warn, error, fatal, panic)."`

	// File is the log formatter for the writer.
	Formatter string `toml:"formatter" comment:"The formatter for the writer (json, text)."`

	// Filename is the file for a file logger.
	Filename string `toml:"filename" comment:"The file for a file logger."`
}

WriterConfig contains configuration for a log writer.

type WriterHook

type WriterHook struct {
	Writer    io.Writer
	LogLevel  log.Level
	Formatter log.Formatter
}

WriterHook is a hook that writes logs of specified LogLevels to specified Writer

func (*WriterHook) Fire

func (h *WriterHook) Fire(entry *log.Entry) error

Fire will be called when some logging function is called with current hook It will format log entry to string and write it to appropriate writer

func (*WriterHook) Levels

func (h *WriterHook) Levels() []log.Level

Levels define on which log levels this hook would trigger

Jump to

Keyboard shortcuts

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