Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LogLevelMap = map[zapcore.Level]int{ zapcore.DebugLevel: 7, zapcore.InfoLevel: 6, zapcore.WarnLevel: 4, zapcore.ErrorLevel: 3, zapcore.DPanicLevel: 2, zapcore.PanicLevel: 1, zapcore.FatalLevel: 0, }
LogLevelMap maps zap logger levels to Graylog (Syslog) levels.
Functions ¶
func ConvertZapLogLevelToGraylog ¶
ConvertZapLogLevelToGraylog converts a Zap log level to a Graylog log level. It takes a string `level` as input and returns an integer corresponding to the Graylog log level. It first parses the input `level` using `zapcore.ParseLevel`. If the parsing is successful, it checks if the parsed level exists in the `LogLevelMap` map. If it exists, it returns the corresponding Graylog log level. If it does not exist, it returns the default Graylog log level 6. If the parsing fails, it also returns the default Graylog log level 6.
func NewZapLogger ¶
func NewZapLogger(address string, useTSL bool, tslConfig *tls.Config, otherZapCores ...zapcore.Core) (*zap.Logger, error)
NewZapLogger creates a new Zap logger with the specified Graylog address and TLS configuration. It takes the following parameters:
- address: the address of the Graylog server
- useTLS: a boolean indicating whether to use TLS for the connection
- tslConfig: the TLS configuration to use (can be nil if useTLS is false)
- otherZapCores: optional additional Zap cores to include in the logger's core
It first initializes a new GelfLogger using the provided address, useTLS, tslConfig, and ProcessZapLoggerFields function. If the GelfLogger initialization is successful, it creates a GelfWriter using the GelfLogger. It then creates a Zap core by adding the GelfWriter to a MultiWriter and creating a Zap core with JSON encoder and InfoLevel. If otherZapCores are provided, it appends the Gelf core to the otherZapCores and creates a Tee core. Otherwise, it creates the Tee core with only the Gelf core. Finally, it creates and returns a new Zap logger with the Tee core. If the GelfLogger initialization fails, it returns nil and the error from the GelfLogger initialization.
Types ¶
This section is empty.