Documentation
¶
Index ¶
- func Get(ctx context.Context) *zap.Logger
- func HTTPMiddleware(next http.Handler) http.Handler
- func NewContext(ctx context.Context, l *zap.Logger) context.Context
- func SQLMiddleware(ctx context.Context, queryName, query string, args ...interface{}) (context.Context, sqlMiddleware.MiddlewareEnd, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns the logger wrapped with the given context. This function is intended to be used as a mechanism for adding scoped arbitrary logging information to the logger. If a nil context is passed, the default global logger is returned.
func HTTPMiddleware ¶ added in v0.3.0
HTTPMiddleware logs a series of standard attributes for every HTTP request and attaches a logger onto the request context.
On inbound request received these attributes include:
* The remote address of the client * The HTTP Method utilized
On outbound response return these attributes include all of the above as well as: * HTTP response code Note that this middleware must be attached after writer.StatusRecorderMiddleware for HTTP response code logging to function and after tracing.HTTPMiddleware for trace ids to show up in logs.
func NewContext ¶
NewContext creates and returns a new context with a wrapped logger. If a logger is not provided, the context returned will contain the global logger. This concept is useful if you wish for all downstream logs from the site of a given context to include some contextual fields or use a sub-logger. For example, once your application has unpacked the Trace ID, you may wish to log that information with every future request.
func SQLMiddleware ¶ added in v0.3.0
func SQLMiddleware(ctx context.Context, queryName, query string, args ...interface{}) (context.Context, sqlMiddleware.MiddlewareEnd, error)
SQLMiddleware debug logs requests made against SQL databases.
Types ¶
type Config ¶
type Config struct {
UseDevelopmentLogger bool // If true, use default zap development logger settings
OutputPaths []string // List of locations where logs should be placed. Defaults to stdout
ErrorOutputPaths []string // List of locations where error logs should be placed. Defaults to stderr
Level string // The level at which logs should be produced. Defaults to INFO
SamplingInitial int // Initial sampling rate for the logger for each cycle
SamplingThereafter int // Sampling rate after that initial cap is hit, per cycle
Encoding string // One of "json" or "console"
Fields map[string]interface{} // These fields will be applied to all logs. Strongly recommend `version` at a minimum.
Cores []zapcore.Core // Provides optional functionality to allow users to Tee log output to additional Log cores
Options []zap.Option // Users may specify any additional zap logger options which override defaults
// contains filtered or unexported fields
}
Config defines the necessary configuration for instantiating a Logger
func (Config) InitializeLogger ¶
InitializeLogger sets up the logger. This function should be called as soon as possible. Any use of the logger provided by this package will be a nop until this function is called.
func (*Config) RegisterFlags ¶
RegisterFlags register Logging flags with pflags