log

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2019 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context) *zap.Logger

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 Middleware

func Middleware(sr *writer.StatusRecorder, r *http.Request) (func(), *http.Request)

Middleware 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

func NewContext(ctx context.Context, fields ...zapcore.Field) context.Context

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.

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

func (c *Config) InitializeLogger() error

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

func (c Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags register Logging flags with pflags

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL