Documentation
¶
Index ¶
- func AddFlags(v *viper.Viper, f *pflag.FlagSet) error
- func LoggerFromContext(ctx context.Context) *zap.Logger
- func LoggerWithFieldsFromContext(ctx context.Context) *zap.Logger
- func LoggerWithFieldsFromNamespaceContext(ctx context.Context, namespaces ...string) *zap.Logger
- func TagsToFields(tags []*tag.Tag) []zap.Field
- func WithLogger(ctx context.Context, logger *zap.Logger) context.Context
- type CallerEncoder
- type Config
- type DurationEncoder
- type EncoderConfig
- type Format
- type Level
- type LevelEncoder
- type NameEncoder
- type SamplingConfig
- type TimeEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFlags ¶
AddFlags adds flags to the given viper and pflag.FlagSet. Sets - all viper keys with "log." prefix - all environment variables with "LOG_" prefix - all flags with "log-" prefix
func LoggerFromContext ¶
LoggerFromContext returns a logger from the given context with the default namespace tags attached to it
func LoggerWithFieldsFromContext ¶
LoggerWithFieldsFromContext returns a logger from the given context with the default namespace tags attached to it
func LoggerWithFieldsFromNamespaceContext ¶
LoggerWithFieldsFromNamespaceContext returns a logger from the given context. It loads the tags from the provided tags namespace and adds them to the logger.
func TagsToFields ¶
TagsToFields converts a slice of tags to zap fields
Types ¶
type CallerEncoder ¶ added in v0.2.1
type CallerEncoder int
const ( CallerEncoderFull CallerEncoder = iota CallerEncoderShort )
func ParseCallerEncoder ¶ added in v0.2.1
func ParseCallerEncoder(encoder string) (CallerEncoder, error)
func (CallerEncoder) String ¶ added in v0.3.5
func (c CallerEncoder) String() string
type Config ¶ added in v0.2.1
type Config struct { Format *Format `key:"format,omitempty" desc:"Log format"` Level *Level `key:"level,omitempty" desc:"Minimum enabled logging level"` EnableStacktrace *bool `` /* 127-byte string literal not displayed */ EnableCaller *bool `key:"enable-caller,omitempty" env:"ENABLE_CALLER" flag:"enable-caller" desc:"Enable caller"` Encoder *EncoderConfig `key:"encoding,omitempty" flag:"encoding" env:"ENCODING" desc:"Encoding: "` Sampling *SamplingConfig `key:"sampling,omitempty" desc:"Sampling: "` OutputPaths *[]*string `key:"output-paths,omitempty" env:"OUTPUT_PATHS" flag:"output" desc:"List of URLs or file paths to write logging output to"` ErrorOutputPaths *[]*string `` /* 132-byte string literal not displayed */ }
Config is the configuration to create a zap.Config.
func DefaultConfig ¶ added in v0.3.5
func DefaultConfig() *Config
DefaultConfig returns a default Config.
func (*Config) Env ¶ added in v0.3.5
Env returns the environment variables for the given Config. All environment variables are prefixed with "LOG_".
type DurationEncoder ¶ added in v0.2.1
type DurationEncoder int
const ( DurationEncoderString DurationEncoder = iota DurationEncoderNanos DurationEncoderMillis DurationEncoderSeconds )
func ParseDurationEncoder ¶ added in v0.2.1
func ParseDurationEncoder(encoder string) (DurationEncoder, error)
func (DurationEncoder) String ¶ added in v0.3.5
func (d DurationEncoder) String() string
type EncoderConfig ¶ added in v0.2.1
type EncoderConfig struct { MessageKey *string `` /* 130-byte string literal not displayed */ LevelKey *string `key:"level-key,omitempty" env:"LEVEL_KEY" flag:"level-key" desc:"Key for the log level (if empty, the level is omitted)"` TimeKey *string `key:"time-key,omitempty" env:"TIME_KEY" flag:"time-key" desc:"Key for the log timestamp (if empty, the timestamp is omitted)"` NameKey *string `` /* 129-byte string literal not displayed */ CallerKey *string `key:"caller-key,omitempty" env:"CALLER_KEY" flag:"caller-key" desc:"Key for the log caller (if empty, the caller is omitted)"` FunctionKey *string `` /* 135-byte string literal not displayed */ StacktraceKey *string `` /* 145-byte string literal not displayed */ SkipLineEnding *bool `key:"skip-line-ending,omitempty" env:"SKIP_LINE_ENDING" flag:"skip-line-ending" desc:"Skip the line ending"` LineEnding *string `key:"line-ending,omitempty" env:"LINE_ENDING" flag:"line-ending" desc:"Line ending"` LevelEncoder *LevelEncoder `` /* 175-byte string literal not displayed */ TimeEncoder *TimeEncoder `` /* 191-byte string literal not displayed */ DurationEncoder *DurationEncoder `` /* 168-byte string literal not displayed */ CallerEncoder *CallerEncoder `` /* 147-byte string literal not displayed */ NameEncoder *NameEncoder `` /* 146-byte string literal not displayed */ ConsoleSeparator *string `` /* 133-byte string literal not displayed */ }
func (*EncoderConfig) EncoderConfig ¶ added in v0.3.5
func (cfg *EncoderConfig) EncoderConfig() *zapcore.EncoderConfig
type LevelEncoder ¶ added in v0.2.1
type LevelEncoder int
const ( LevelEncoderCapital LevelEncoder = iota LevelEncoderCapitalColor LevelEncoderColor LevelEncoderLowercase )
func ParseLevelEncoder ¶ added in v0.2.1
func ParseLevelEncoder(encoder string) (LevelEncoder, error)
func (LevelEncoder) String ¶ added in v0.3.5
func (l LevelEncoder) String() string
type NameEncoder ¶ added in v0.2.1
type NameEncoder int
const ( NameEncoderFull NameEncoder = iota NameEncoderShort )
func ParseNameEncoder ¶ added in v0.2.1
func ParseNameEncoder(encoder string) (NameEncoder, error)
func (NameEncoder) String ¶ added in v0.3.5
func (n NameEncoder) String() string
type SamplingConfig ¶ added in v0.2.3
type SamplingConfig struct { Initial *int `key:"initial,omitempty" desc:"Number of log entries with the same level and message to log before dropping entries"` Thereafter *int `key:"thereafter,omitempty" desc:"After the initial number of entries, every Mth entry is logged and the rest are dropped"` }
type TimeEncoder ¶ added in v0.2.1
type TimeEncoder int
const ( TimeEncoderRFC3339Nano TimeEncoder = iota TimeEncoderRFC3339 TimeEncoderISO8601 TimeEncoderMillis TimeEncoderNanos TimeEncoderTime )
func ParseTimeEncoder ¶ added in v0.2.1
func ParseTimeEncoder(encoder string) (TimeEncoder, error)
func (TimeEncoder) String ¶ added in v0.3.5
func (t TimeEncoder) String() string