Documentation ¶
Overview ¶
Package plog is a simple logging package for Go. It is based on the slog package from the Go standard library. It adds a few convienence features, such as the ability to
- log to graylog
- log more detailed info in development mode
- log to multiple writers (eg. stdout/text, stdout/json, stdout/devel, graylog)
Package prettylog provides a pretty logger for slog. inspired by https://github.com/dusted-go/logging/blob/main/prettylog/prettylog.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogger ¶
func NewLogger(cfg *LoggingConfig) *slog.Logger
NewLogger creates a new logger based on the LoggingConfig.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewPrettyLogHandler ¶
func NewPrettyLogHandler(opts *slog.HandlerOptions) *Handler
NewHandler returns a new Handler.
type LoggingConfig ¶
type LoggingConfig struct { // Level is the log level. It is set by GuessLogLevel() based on the LevelStr field. Level slog.Leveler // LevelStr is the string representation of the log level. Possible values: DEBUG, INFO, WARN, ERROR LevelStr string `envconfig:"LOG_LEVEL" default:"INFO" description:"minimum log level to log"` // Handler is the log handler. Possible values: DEV, TEXT, JSON, GRAYLOG, GRAYLOGONLY // DEV: pretty log handler for development sets log level to DEBUG // and adds source code location to log messages // TEXT: text log handler prints structured log messages to stdout in human readable format // JSON: json log handler prints structured log messages to stdout in json format // GRAYLOG: graylog log handler sends structured log messages to a graylog server // log messages are sent via UDP and printed to stdout // GRAYLOGONLY: graylog log handler sends structured log messages to a graylog server // log messages are sent via UDP only. No log messages are printed to stdout Handler string `` /* 130-byte string literal not displayed */ // GraylogHost is the hostname or IP address of the graylog server. (only used if LOG_HANDLER=GRAYLOG) GraylogHost string `envconfig:"LOG_GRAYLOG_HOST" default:"localhost" description:"hostname or ip address of the graylog server"` // GraylogPort is the port (UDP) of the graylog server. (only used if LOG_HANDLER=GRAYLOG) GraylogPort string `envconfig:"LOG_GRAYLOG_PORT" default:"12201" description:"port (UDP) of the graylog server"` }
LoggingConfig is the configuration for the logger.
Click to show internal directories.
Click to hide internal directories.