Documentation
¶
Index ¶
- func Get(ctx context.Context) *zap.Logger
- func HTTPMiddleware(sr *writer.StatusRecorder, r *http.Request) (func(), *http.Request)
- func NewContext(ctx context.Context, fields ...zapcore.Field) 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.
On inbound request received these attributes include:
* The remote address of the client * The HTTP Method utilized * The hostname specified on this request * The port specified on this request
On outbound response return these attributes include all of the above as well as: * HTTP response code
func NewContext ¶
NewContext creates and returns a new context with a wrapped logger. If fields are specified, all future invocations of the context logger will include those fields as well. This concept is useful if you wish for all downstream logs from the site of a given context to include some contextual information. 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