Documentation ¶
Overview ¶
message from the author:
+--------------------------------------------------------------+ | * * * ░░░░░░░░░░░░░░░░░░░░ Hello ░░░░░░░░░░░░░░░░░░░░░░░░░░| +--------------------------------------------------------------+ | | | ++ ______________________________________ | | ++++ / \ | | ++++ | | | | ++++++++++ | Feel free to contribute to this | | | +++ | | project or contact me on | | | ++ | | manfred.life if you like this | | | + -== ==| | project! | | | ( <*> <*> | | | | | | /| :) | | | | _) / | | | | | +++ / \______________________________________/ | | \ =+ / | | \ + | | |\++++++ | | | ++++ ||// | | ___| |___ _||/__ __| | / --- \ \| ||| __ _ ___ __ __/ /| |/ | | \ \ / / ' \/ _ \/ // / / | || | | | | | /_/_/_/\___/\_,_/_/ | +--------------------------------------------------------------+
Example ¶
package main import ( "moul.io/zapconfig" ) func main() { logger := zapconfig.Configurator{}.MustBuild() logger.Info("hello!") }
Output:
Example (Configuration) ¶
package main import ( "go.uber.org/zap/zapcore" "moul.io/zapconfig" ) func main() { logger := zapconfig.New(). EnableStacktrace(). SetLevel(zapcore.DebugLevel). SetOutputPath("stderr"). SetOutputPaths([]string{"stderr", "stdout", "./path/to/log.txt"}). SetPreset("light-console"). MustBuild() logger.Info("hello!") }
Output:
Index ¶
- Variables
- type Configurator
- func (c Configurator) Build() (*zap.Logger, error)
- func (c Configurator) Config() (zap.Config, error)
- func (c *Configurator) EnableStacktrace() *Configurator
- func (c Configurator) IsEmpty() bool
- func (c Configurator) MustBuild() *zap.Logger
- func (c *Configurator) SetLevel(level zapcore.Level) *Configurator
- func (c *Configurator) SetOutputPath(dest string) *Configurator
- func (c *Configurator) SetOutputPaths(dests []string) *Configurator
- func (c *Configurator) SetPreset(name string) *Configurator
- func (c Configurator) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var AvailablePresets = []string{"console", "json", "light-console", "light-json", "testing"}
AvailablePresets is the list of preset supported by `SetPreset`.
Functions ¶
This section is empty.
Types ¶
type Configurator ¶
type Configurator struct {
// contains filtered or unexported fields
}
Configurator is the main object of this package. Leaving it empty will generate an opinionated sane default zap.Config.
func (Configurator) Build ¶
func (c Configurator) Build() (*zap.Logger, error)
BuildLogger returns a configured *zap.Logger.
func (Configurator) Config ¶
func (c Configurator) Config() (zap.Config, error)
Config builds a zap.Config.
func (*Configurator) EnableStacktrace ¶ added in v1.2.0
func (c *Configurator) EnableStacktrace() *Configurator
EnableStacktrace forces stacktraces to be enabled.
func (Configurator) IsEmpty ¶
func (c Configurator) IsEmpty() bool
IsEmpty checks whether the Configurator isn't touched (default value) or if it was modified.
func (Configurator) MustBuild ¶
func (c Configurator) MustBuild() *zap.Logger
func (*Configurator) SetLevel ¶
func (c *Configurator) SetLevel(level zapcore.Level) *Configurator
SetLevel sets the minimal logging level.
func (*Configurator) SetOutputPath ¶
func (c *Configurator) SetOutputPath(dest string) *Configurator
SetOutputPath sets zap.Config.OutputPaths and c.Config.ErrorOutputPaths with the given path.
func (*Configurator) SetOutputPaths ¶
func (c *Configurator) SetOutputPaths(dests []string) *Configurator
SetOutputPaths sets zap.Config.OutputPaths and c.Config.ErrorOutputPaths with the given paths.
func (*Configurator) SetPreset ¶ added in v1.3.0
func (c *Configurator) SetPreset(name string) *Configurator
SetPreset configures various things based on just a keyword.