Documentation
¶
Overview ¶
Package simplog provides a simple logging library for Go. It is factually not a logger itself, but rather helps you by providing simple and opinionated ways quickly set up uber-go/zap as a logger.
Usage:
package main import "github.com/nikoksr/simplog" func main() { // Using the manual configuration; alternatively you can use NewClientLogger() or NewServerLogger(). logger := simplog.NewWithOptions(&simplog.Options{ Debug: false, IsServer: true, }) // At this point, you're using a zap.SugaredLogger and can use it as you would normally do. logger.Info("You're awesome!") logger.Warn("Coffee is almost empty!") logger.Error("Unable to operate, caffein levels too low.") }
Index ¶
- func FromContext(ctx context.Context) *zap.SugaredLogger
- func NewClientLogger(debug bool) *zap.SugaredLogger
- func NewServerLogger(debug bool) *zap.SugaredLogger
- func NewWithOptions(opts *Options) *zap.SugaredLogger
- func SetDPanicSymbol(symbol string)
- func SetDebugSymbol(symbol string)
- func SetErrorSymbol(symbol string)
- func SetFatalSymbol(symbol string)
- func SetInfoSymbol(symbol string)
- func SetPanicSymbol(symbol string)
- func SetWarnSymbol(symbol string)
- func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶ added in v0.7.0
func FromContext(ctx context.Context) *zap.SugaredLogger
FromContext returns the logger from the given context. If the context does not contain a logger, the default logger is returned. If the context is nil, the default logger is returned.
func NewClientLogger ¶ added in v0.7.0
func NewClientLogger(debug bool) *zap.SugaredLogger
NewClientLogger returns a new logger that's meant to be used by client-type applications. It uses a human-readable format.
func NewServerLogger ¶ added in v0.7.0
func NewServerLogger(debug bool) *zap.SugaredLogger
NewServerLogger returns a new logger that's meant to be used by servers. It uses structured logging when run in production, and a human-readable format when run in development.
func NewWithOptions ¶ added in v0.7.0
func NewWithOptions(opts *Options) *zap.SugaredLogger
NewWithOptions returns a new logger with the given options. If the options are nil, the default logger is returned.
func SetDPanicSymbol ¶ added in v0.8.0
func SetDPanicSymbol(symbol string)
SetDPanicSymbol sets the dpanic symbol.
func SetDebugSymbol ¶ added in v0.7.0
func SetDebugSymbol(symbol string)
SetDebugSymbol sets the debug symbol.
func SetErrorSymbol ¶ added in v0.7.0
func SetErrorSymbol(symbol string)
SetErrorSymbol sets the error symbol.
func SetFatalSymbol ¶ added in v0.8.0
func SetFatalSymbol(symbol string)
SetFatalSymbol sets the fatal symbol.
func SetInfoSymbol ¶ added in v0.7.0
func SetInfoSymbol(symbol string)
SetInfoSymbol sets the info symbol.
func SetPanicSymbol ¶ added in v0.8.0
func SetPanicSymbol(symbol string)
SetPanicSymbol sets the panic symbol.
func SetWarnSymbol ¶ added in v0.7.0
func SetWarnSymbol(symbol string)
SetWarnSymbol sets the warning symbol.
func WithLogger ¶ added in v0.7.0
WithLogger returns a new context.Context with the given logger.