Documentation
¶
Index ¶
- func AddFlags(v *viper.Viper, f *pflag.FlagSet, hooks ...config.EncodeHookFunc) 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 ¶
type CallerEncoder int
const ( CallerEncoderFull CallerEncoder = iota CallerEncoderShort )
func ParseCallerEncoder ¶
func ParseCallerEncoder(encoder string) (CallerEncoder, error)
func (CallerEncoder) MarshalJSON ¶ added in v0.9.1
func (c CallerEncoder) MarshalJSON() ([]byte, error)
func (CallerEncoder) String ¶
func (c CallerEncoder) String() string
type Config ¶
type Config struct {
Format *Format `key:"format,omitempty" desc:"Log format"`
Level *Level `key:"level,omitempty" desc:"Minimum enabled logging level"`
EnableStacktrace *bool `` /* 126-byte string literal not displayed */
EnableCaller *bool `key:"enableCaller,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:"outputPaths,omitempty" env:"OUTPUT_PATHS" flag:"output" desc:"List of URLs or file paths to write logging output to"`
ErrorOutputPaths *[]*string `` /* 130-byte string literal not displayed */
}
Config is the configuration to create a zap.Config.
func (*Config) Env ¶
Env returns the environment variables for the given Config. All environment variables are prefixed with "LOG_".
func (*Config) MarshalJSON ¶ added in v0.9.1
type DurationEncoder ¶
type DurationEncoder int
const ( DurationEncoderString DurationEncoder = iota DurationEncoderNanos DurationEncoderMillis DurationEncoderSeconds )
func ParseDurationEncoder ¶
func ParseDurationEncoder(encoder string) (DurationEncoder, error)
func (DurationEncoder) MarshalJSON ¶ added in v0.9.1
func (d DurationEncoder) MarshalJSON() ([]byte, error)
func (DurationEncoder) String ¶
func (d DurationEncoder) String() string
type EncoderConfig ¶
type EncoderConfig struct {
MessageKey *string `` /* 129-byte string literal not displayed */
LevelKey *string `key:"levelKey,omitempty" env:"LEVEL_KEY" flag:"level-key" desc:"Key for the log level (if empty, the level is omitted)"`
TimeKey *string `key:"timeKey,omitempty" env:"TIME_KEY" flag:"time-key" desc:"Key for the log timestamp (if empty, the timestamp is omitted)"`
NameKey *string `` /* 128-byte string literal not displayed */
CallerKey *string `key:"callerKey,omitempty" env:"CALLER_KEY" flag:"caller-key" desc:"Key for the log caller (if empty, the caller is omitted)"`
FunctionKey *string `` /* 134-byte string literal not displayed */
StacktraceKey *string `` /* 144-byte string literal not displayed */
SkipLineEnding *bool `key:"skipLineEnding,omitempty" env:"SKIP_LINE_ENDING" flag:"skip-line-ending" desc:"Skip the line ending"`
LineEnding *string `key:"lineEnding,omitempty" env:"LINE_ENDING" flag:"line-ending" desc:"Line ending"`
LevelEncoder *LevelEncoder `` /* 174-byte string literal not displayed */
TimeEncoder *TimeEncoder `` /* 190-byte string literal not displayed */
DurationEncoder *DurationEncoder `` /* 167-byte string literal not displayed */
CallerEncoder *CallerEncoder `` /* 146-byte string literal not displayed */
NameEncoder *NameEncoder `` /* 145-byte string literal not displayed */
ConsoleSeparator *string `` /* 132-byte string literal not displayed */
}
func (*EncoderConfig) EncoderConfig ¶
func (cfg *EncoderConfig) EncoderConfig() *zapcore.EncoderConfig
func (*EncoderConfig) MarshalJSON ¶ added in v0.9.1
func (cfg *EncoderConfig) MarshalJSON() ([]byte, error)
type LevelEncoder ¶
type LevelEncoder int
const ( LevelEncoderCapital LevelEncoder = iota LevelEncoderCapitalColor LevelEncoderColor LevelEncoderLowercase )
func ParseLevelEncoder ¶
func ParseLevelEncoder(encoder string) (LevelEncoder, error)
func (LevelEncoder) MarshalJSON ¶ added in v0.9.1
func (l LevelEncoder) MarshalJSON() ([]byte, error)
func (LevelEncoder) String ¶
func (l LevelEncoder) String() string
type NameEncoder ¶
type NameEncoder int
const ( NameEncoderFull NameEncoder = iota NameEncoderShort )
func ParseNameEncoder ¶
func ParseNameEncoder(encoder string) (NameEncoder, error)
func (NameEncoder) MarshalJSON ¶ added in v0.9.1
func (n NameEncoder) MarshalJSON() ([]byte, error)
func (NameEncoder) String ¶
func (n NameEncoder) String() string
type SamplingConfig ¶
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"`
}
func (*SamplingConfig) MarshalJSON ¶ added in v0.9.1
func (cfg *SamplingConfig) MarshalJSON() ([]byte, error)
type TimeEncoder ¶
type TimeEncoder int
const ( TimeEncoderRFC3339Nano TimeEncoder = iota TimeEncoderRFC3339 TimeEncoderISO8601 TimeEncoderMillis TimeEncoderNanos TimeEncoderTime )
func ParseTimeEncoder ¶
func ParseTimeEncoder(encoder string) (TimeEncoder, error)
func (TimeEncoder) MarshalJSON ¶ added in v0.9.1
func (t TimeEncoder) MarshalJSON() ([]byte, error)
func (TimeEncoder) String ¶
func (t TimeEncoder) String() string