{"modulePath":"github.com/vcabbage/kit","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package level\n\nPackage level implements leveled logging on top of package log. To use the level package, create a logger as per normal in your func main, and wrap it with level.NewFilter.\n\n\tvar logger log.Logger\n\tlogger = log.NewLogfmtLogger(os.Stderr)\n\tlogger = level.NewFilter(logger, level.AllowInfoAndAbove()) // \u003c--\n\tlogger = log.With(logger, \"ts\", log.DefaultTimestampUTC)\n\nThen, at the callsites, use one of the level.Debug, Info, Warn, or Error helper methods to emit leveled log events.\n\n\tlogger.Log(\"foo\", \"bar\") // as normal, no level\n\tlevel.Debug(logger).Log(\"request_id\", reqID, \"trace_data\", trace.Get())\n\tif value \u003e 100 {\n\t    level.Error(logger).Log(\"value\", value)\n\t}\n\nNewFilter allows precise control over what happens when a log event is emitted without a level key, or if a squelched level is used. Check the Option functions for details.\n\n## Functions\n\n```go\nfunc Debug(logger log.Logger) log.Logger\n```\nDebug returns a logger that includes a Key/DebugValue pair.\n\n```go\nfunc Error(logger log.Logger) log.Logger\n```\nError returns a logger that includes a Key/ErrorValue pair.\n\n```go\nfunc Info(logger log.Logger) log.Logger\n```\nInfo returns a logger that includes a Key/InfoValue pair.\n\n```go\nfunc Key() interface{}\n```\nKey returns the unique key added to log events by the loggers in this package.\n\n```go\nfunc NewFilter(next log.Logger, options ...Option) log.Logger\n```\nNewFilter wraps next and implements level filtering. See the commentary on the Option functions for a detailed description of how to configure levels. If no options are provided, all leveled log events created with Debug, Info, Warn or Error helper methods are squelched and non-leveled log events are passed to next unmodified.\n\n```go\nfunc NewInjector(next log.Logger, level Value) log.Logger\n```\nNewInjector wraps next and returns a logger that adds a Key/level pair to the beginning of log events that don't already contain a level. In effect, this gives a default level to logs without a level.\n\n```go\nfunc Warn(logger log.Logger) log.Logger\n```\nWarn returns a logger that includes a Key/WarnValue pair.\n\n## Types\n\n```go\ntype Option func(*logger)\n```\nOption sets a parameter for the leveled logger.\n\n```go\nfunc AllowAll() Option\n```\nAllowAll is an alias for AllowDebug.\n\n```go\nfunc AllowDebug() Option\n```\nAllowDebug allows error, warn, info and debug level log events to pass.\n\n```go\nfunc AllowError() Option\n```\nAllowError allows only error level log events to pass.\n\n```go\nfunc AllowInfo() Option\n```\nAllowInfo allows error, warn and info level log events to pass.\n\n```go\nfunc AllowNone() Option\n```\nAllowNone allows no leveled log events to pass.\n\n```go\nfunc AllowWarn() Option\n```\nAllowWarn allows error and warn level log events to pass.\n\n```go\nfunc ErrNoLevel(err error) Option\n```\nErrNoLevel sets the error to return from Log when it squelches a log event with no level. By default, ErrNoLevel is nil; in this case the log event is squelched with no error.\n\n```go\nfunc ErrNotAllowed(err error) Option\n```\nErrNotAllowed sets the error to return from Log when it squelches a log event disallowed by the configured Allow\\[Level] option. By default, ErrNotAllowed is nil; in this case the log event is squelched with no error.\n\n```go\nfunc SquelchNoLevel(squelch bool) Option\n```\nSquelchNoLevel instructs Log to squelch log events with no level, so that they don't proceed through to the wrapped logger. If SquelchNoLevel is set to true and a log event is squelched in this way, the error value configured with ErrNoLevel is returned to the caller.\n\n```go\ntype Value interface {\n\tString() string\n\t// contains filtered or unexported methods\n}\n```\nValue is the interface that each of the canonical level values implement. It contains unexported methods that prevent types from other packages from implementing it and guaranteeing that NewFilter can distinguish the levels defined in this package from all other values.\n\n```go\nfunc DebugValue() Value\n```\nDebugValue returns the unique value added to log events by Warn.\n\n```go\nfunc ErrorValue() Value\n```\nErrorValue returns the unique value added to log events by Error.\n\n```go\nfunc InfoValue() Value\n```\nInfoValue returns the unique value added to log events by Info.\n\n```go\nfunc WarnValue() Value\n```\nWarnValue returns the unique value added to log events by Warn.\n\n","path":"github.com/vcabbage/kit/log/level","name":"level","synopsis":"Package level implements leveled logging on top of package log.","isRedistributable":true}
