Documentation ¶
Overview ¶
Package ecszap provides a formatter to be used with the go.uber.org/zap logger library that helps creating Elastic Common Schema (ECS) conformant log entries.
Index ¶
- func ECSCompatibleEncoderConfig(cfg zapcore.EncoderConfig) zapcore.EncoderConfig
- func EpochMicrosTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func FullCallerEncoder(c zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func NewCore(cfg EncoderConfig, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
- func ShortCallerEncoder(c zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func WrapCore(c zapcore.Core) zapcore.Core
- func WrapCoreOption() zap.Option
- type CallerEncoder
- type EncoderConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ECSCompatibleEncoderConfig ¶ added in v0.2.0
func ECSCompatibleEncoderConfig(cfg zapcore.EncoderConfig) zapcore.EncoderConfig
ECSCompatibleEncoderConfig takes an existing zapcore.EncoderConfig and sets ECS relevant configuration options to ECS conformant values. The returned zapcore.EncoderConfig can be used to create an ECS conformant encoder. Be aware that this will always replace any set EncodeCaller function with the ecszap.ShortCallerEncoder. This is a pure convenience function for making a transition from existing an zap logger to an ECS conformant zap loggers easier. It is recommended to make use of the ecszap.EncoderConfig whenever possible.
func EpochMicrosTimeEncoder ¶
func EpochMicrosTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
EpochMicrosTimeEncoder encodes a given time in microseconds.
func FullCallerEncoder ¶
func FullCallerEncoder(c zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
FullCallerEncoder serializes the file name, line and function from the caller in an ECS compliant way; serializing the full path of the file name using the underlying zapcore.EntryCaller.
func NewCore ¶
func NewCore(cfg EncoderConfig, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
NewCore creates a zapcore.Core that uses an ECS conformant JSON encoder. This is the safest way to create an ECS compatible core.
func ShortCallerEncoder ¶
func ShortCallerEncoder(c zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes the file name, line and function from the caller in an ECS compliant way; removing everything except the final directory from the file name by calling the underlying zapcore.EntryCaller TrimmedPath().
func WrapCore ¶
WrapCore wraps a core with ECS core functionality and returns a zapcore.Core. For ECS compatibility, ensure that the wrapped zapcore.Core uses an encoder that is created from an ECS compatible configuration. For further details check out ecszap.EncoderConfig or ecszap.ECSCompatibleEncoderConfig.
func WrapCoreOption ¶ added in v1.0.0
WrapCoreOption returns a zap.Option, wrapping the underlying zapcore.Core.
Types ¶
type CallerEncoder ¶
type CallerEncoder func(zapcore.EntryCaller, zapcore.PrimitiveArrayEncoder)
CallerEncoder is equivalent to zapcore.CallerEncoder, except that its UnmarshalText method uses FullCallerEncoder and ShortCallerEncoder from this package instead, in order to encode callers in the ECS format.
func (*CallerEncoder) UnmarshalText ¶
func (e *CallerEncoder) UnmarshalText(text []byte) error
UnmarshalText creates a CallerEncoder function, `full` is unmarshalled to FullCallerEncoder, defaults to ShortCallerEncoder,
type EncoderConfig ¶
type EncoderConfig struct { // EnableName controls if a logger's name should be serialized // when available. If enabled, the EncodeName configuration is // used for serialization. EnableName bool `json:"enableName" yaml:"enableName"` // EnableStackTrace controls if a stack trace should be serialized when available. EnableStackTrace bool `json:"enableStackTrace" yaml:"enableStackTrace"` // EnableCaller controls if the entry caller should be serialized. // If enabled, the EncodeCaller configuration is used for serialization. EnableCaller bool `json:"enableCaller" yaml:"enableCaller"` // LineEnding defines the string used for line endings. LineEnding string `json:"lineEnding" yaml:"lineEnding"` // EncodeName defines how to encode a loggers name. // It will only be applied if EnableName is set to true. EncodeName zapcore.NameEncoder `json:"nameEncoder" yaml:"nameEncoder"` // EncodeLevel sets the log level for which any context should be logged. EncodeLevel zapcore.LevelEncoder `json:"levelEncoder" yaml:"levelEncoder"` // EncodeDuration sets the format for encoding time.Duration values. EncodeDuration zapcore.DurationEncoder `json:"durationEncoder" yaml:"durationEncoder"` // EncodeCaller defines how an entry caller should be serialized. // It will only be applied if EnableCaller is set to true. EncodeCaller CallerEncoder `json:"callerEncoder" yaml:"callerEncoder"` }
EncoderConfig exports all non ECS related configurable settings. The configuration can be used to create an ECS compatible zapcore.Core
func NewDefaultEncoderConfig ¶
func NewDefaultEncoderConfig() EncoderConfig
NewDefaultEncoderConfig returns an EncoderConfig with default settings.
func (EncoderConfig) ToZapCoreEncoderConfig ¶ added in v0.2.0
func (cfg EncoderConfig) ToZapCoreEncoderConfig() zapcore.EncoderConfig
ToZapCoreEncoderConfig transforms the ecszap.EncoderConfig into a zapcore.EncoderConfig