zaplogger

package
v0.3.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

LogLevelMap maps zap logger levels to Graylog (Syslog) levels.

Functions

func ConvertZapLogLevelToGraylog

func ConvertZapLogLevelToGraylog(level string) int

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.

func ProcessZapLoggerFields

func ProcessZapLoggerFields(fields map[string]interface{}) (int, float64, []byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL