zerologger

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

LogLevelMap maps zerolog levels to Graylog (Syslog) levels.

Functions

func ConvertZerologLevelToGraylog

func ConvertZerologLevelToGraylog(level string) int

ConvertZerologLevelToGraylog converts a zerolog level to the equivalent Graylog (Syslog) level.

func NewZeroLogger

func NewZeroLogger(address string, useTSL bool, tslConfig *tls.Config, otherZeroLogWriter ...io.Writer) (zerolog.Logger, error)

NewZeroLogger initializes and returns a zerolog logger with a Graylog (Syslog) writer. It takes the following arguments: - address: the address of the Graylog server - useTLS: a boolean indicating whether to use TLS for the connection - tslConfig: a *tls.Config object to configure the TLS connection (optional) - otherZeroLogWriter: zero or more additional io.Writer objects to write logs to (optional) The logger is created in the following steps: 1. The gelflogger.NewLogger function is called with the given address, useTLS, tslConfig, and ProcessZerologFields to create a gelflogger.Logger object. 2. If the gelflogger.Logger initialization is successful, a gelflogger.GelfWriter is created with the graylogLogger. 3. If otherZeroLogWriter is not nil, a new slice is created with only the gelfWriter. Otherwise, otherZeroLogWriter remains unchanged. 4. The zerolog.TimeFieldFormat is set to a GELF compatible timestamp format. 5. A zerolog.MultiLevelWriter is created with otherZeroLogWriter as the variadic argument. 6. A zerolog.Logger is created with the multiLevelWriter, Timestamp, and Logger options.

Example usage:

logger, err := NewZeroLogger("graylog.example.com:12201", true, nil, os.Stdout)
if err != nil {
  // handle error
}
logger.Info().Msg("Hello, World!")

func ProcessZerologFields

func ProcessZerologFields(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