logger

package
v0.5.2-0...-d95c312 Latest Latest
Warning

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

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

Documentation

Overview

Package logger handles logging.

This is a thing wrapper around inconshreveable's log15. It additionally brings a configuration format (from YAML) with the ability to log to several destinations.

It also brings some conventions like the presence of "module" in each context to be able to filter logs more easily. However, this convention is not really enforced. Once you have a root logger, create sublogger with New and provide a new value for "module".

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfiguration = Configuration{
	Level:         Lvl(log.LvlInfo),
	Console:       false,
	Syslog:        true,
	IncludeCaller: false,
	Format:        FormatPlain,
}

DefaultConfiguration is the default logging configuration.

Functions

func JSONv1Format

func JSONv1Format() log.Format

JSONv1Format formats log records as JSONv1 objects separated by newlines.

func New

func New(config Configuration, additionalHandler log.Handler, prefix string) (log.Logger, error)

New creates a new logger from a configuration.

Types

type Configuration

type Configuration struct {
	Level         Lvl
	Console       bool
	Syslog        bool
	IncludeCaller bool `yaml:"include_caller,omitempty"`
	Format        LogFormat
	Files         []LogFile
}

Configuration if the configuration for logger.

The ability to override log levels for some modules is currently missing.

func (*Configuration) UnmarshalYAML

func (configuration *Configuration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML parses a logger configuration from YAML.

type LogFile

type LogFile struct {
	Name   string
	Format LogFormat
}

LogFile represents a log file (name and output format).

func (*LogFile) UnmarshalText

func (logFile *LogFile) UnmarshalText(text []byte) error

UnmarshalText parses a path to a logfile from YAML.

This returns an absolute cleaned path.

type LogFormat

type LogFormat int

LogFormat represents an output format for LogFile. Currently, only plain text and JSON are supported.

const (
	// FormatPlain is a plain text log file format.
	FormatPlain LogFormat = iota
	// FormatJSON is a JSONv1 log file format.
	FormatJSON
)

func (*LogFormat) UnmarshalText

func (level *LogFormat) UnmarshalText(text []byte) error

UnmarshalText parses a log format from YAML.

type Lvl

type Lvl log.Lvl

Lvl is a log level (debug, info, warning, ...)

func (Lvl) String

func (level Lvl) String() string

String transform a level to string.

func (*Lvl) UnmarshalText

func (level *Lvl) UnmarshalText(text []byte) error

UnmarshalText parses a log level from YAML.

Jump to

Keyboard shortcuts

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