Documentation ¶
Overview ¶
Package logging provides a configuration model for logrus.
It introduces hierarchical configuration and hot-reloading of configuration for logrus through viper This means that you can use YAML, TOML, HCL and JSON to configure your loggers, or use env vars. It allows for storing configuration in etcd or consul.
You can configure multiple root level loggers which serve as default logger for that tree. In addition to being the default logger, each child logger created will inherit the configuration from its parents. So you only have to define overrides for things you want to customize.
logging: root: level: debug hooks: - name: journald writer: stderr child1: level: info hooks: - name: file path: ./app.log - name: syslog network: udp host: localhost:514 priority: info alerts: level: error writer: stderr
In this example config there are 2 root loggers defined: root and alerts. Both root loggers use a stderr writer, other writers are stdout and discard.
The logger named root has also one child node that overrides the level property. The hooks property is not an override but instead combines the defined hooks. So the hooks work additive whereas everything else are overrides.
Custom writers:
You can register your own named writers with the RegisterWriter function.
Custom Formatters:
You can register your own formatters with the RegisterFormatter function.
Index ¶
- Variables
- func KnownFormatters() []string
- func KnownHooks() []string
- func KnownWriters() []string
- func RegisterFormatter(name string, factory CreateFormatter)
- func RegisterHook(name string, factory CreateHook)
- func RegisterWriter(name string, factory CreateWriter)
- type CreateFormatter
- type CreateHook
- type CreateWriter
- type Logger
- type Registry
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultWriter is used as fallback when no other writer can be found. // This defaults to writing to stderr, but you can replace it to do something more useful DefaultWriter io.Writer )
var ( // RootName of the root logger, defaults to root RootName string )
Functions ¶
func KnownFormatters ¶
func KnownFormatters() []string
KnownFormatters returns a list of keys for the currently registered formatters
func KnownHooks ¶
func KnownHooks() []string
KnownHooks returns the list of keys for the registered hooks
func KnownWriters ¶
func KnownWriters() []string
KnownWriters returns the list of keys for the registered writers
func RegisterFormatter ¶
func RegisterFormatter(name string, factory CreateFormatter)
RegisterFormatter registers a formatter for use in config files
func RegisterHook ¶
func RegisterHook(name string, factory CreateHook)
RegisterHook for use through configuration system
func RegisterWriter ¶
func RegisterWriter(name string, factory CreateWriter)
RegisterWriter for use through the configuration system When you register a writer with a name that was already present then that writer will get overwritten
Types ¶
type CreateFormatter ¶
CreateFormatter is a factory for creating formatters configured through viper
var ( // DefaultFormatter the fallback formatter when no registered one matches DefaultFormatter CreateFormatter )
type CreateHook ¶
CreateHook creates a hook based on a viper config
type CreateWriter ¶
CreateWriter based on a viper config
type Logger ¶
type Logger interface { logrus.FieldLogger New(string, logrus.Fields) Logger Configure(v *viper.Viper) Fields() logrus.Fields }
Logger is the interface that application use to log against. Ideally you use the logrus.FieldLogger or logrus.StdLogger interfaces in your own code.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
LoggerRegistry represents a registry for known loggers
func NewRegistry ¶
NewRegistry creates a new logger registry
func (*Registry) Get ¶
Get a logger by name, returns nil when logger doesn't exist. GetOK is the safe method to use.
func (*Registry) Root ¶
Root returns the root logger, the name is configurable through the RootName variable
func (*Registry) Writer ¶
func (r *Registry) Writer() *io.PipeWriter
Writer returns the pipe writer for the root logger