Documentation
¶
Overview ¶
Package logger provides the RoadRunner logger plugin backed by log/slog.
It supports multiple output modes (development, production, raw, off/none), per-plugin channel overrides, and file-based output.
Index ¶
Constants ¶
const PluginName = "logs"
PluginName declares plugin name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildResult ¶
BuildResult holds the logger and any resources that need cleanup.
type ChannelConfig ¶
type ChannelConfig struct {
// Dedicated channels per logger. By default logger allocated via named logger.
Channels map[string]*Config `mapstructure:"channels"`
}
ChannelConfig configures loggers per channel.
type Config ¶
type Config struct {
// Mode configures logger based on some default template (development,
// production, raw, off, none).
Mode Mode `mapstructure:"mode"`
// Level is the minimum enabled logging level.
Level string `mapstructure:"level"`
// Format is a custom format string with %placeholder% tokens (e.g.
// "%time% [%level%] %message% %attrs%"). When set, it overrides Mode for
// handler selection.
Format string `mapstructure:"format"`
// TimeFormat is a Go time layout used for the %time% placeholder in a
// custom format string. Defaults to [time.RFC3339].
TimeFormat string `mapstructure:"time_format"`
// LineEnding for log entries. Default: "\n".
LineEnding string `mapstructure:"line_ending"`
// SkipLineEnding determines if the logger should skip appending the default
// line ending to each log entry.
SkipLineEnding bool `mapstructure:"skip_line_ending"`
// Encoding sets the logger's encoding. Valid values are "json" and
// "console".
Encoding string `mapstructure:"encoding"`
// Output is a list of URLs or file paths to write logging output to.
Output []string `mapstructure:"output"`
// ErrorOutput is a list of URLs to write internal logger errors to. The
// default is standard error.
ErrorOutput []string `mapstructure:"err_output"`
}
Config holds the logger configuration for a single channel.
func (*Config) BuildLogger ¶
func (cfg *Config) BuildLogger() (*BuildResult, error)
BuildLogger creates an *slog.Logger from the configuration.
func (*Config) InitDefault ¶
func (cfg *Config) InitDefault()
InitDefault sets default values for empty fields.
type Configurer ¶
type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct.
UnmarshalKey(name string, out any) error
// Has checks if a config section exists.
Has(name string) bool
}
Configurer provides access to the application configuration.
type FormatHandler ¶
type FormatHandler struct {
// contains filtered or unexported fields
}
FormatHandler is an slog.Handler that renders log records according to a user-defined format string containing %placeholder% tokens such as %time%, %level%, %message%, %attrs%, %logger%, %source_file%, %source_line%, and %source_func%.
Unknown placeholders are left in the output verbatim.
func NewFormatHandler ¶
func NewFormatHandler(w io.Writer, opts *FormatHandlerOptions) *FormatHandler
NewFormatHandler returns a FormatHandler that writes to w using the given options. The format string is scanned once to determine which placeholders are present so that expensive operations (source lookup, attr rendering) can be skipped when not needed.
func (*FormatHandler) WithAttrs ¶
func (h *FormatHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new FormatHandler that includes the given attributes in every subsequent record. The current group prefix is baked into attr keys so that groups added later do not retroactively affect them.
func (*FormatHandler) WithGroup ¶
func (h *FormatHandler) WithGroup(name string) slog.Handler
WithGroup returns a new FormatHandler that qualifies subsequent attributes with the given group name using dot-separated keys.
type FormatHandlerOptions ¶
type FormatHandlerOptions struct {
// Level is the minimum enabled logging level.
Level slog.Leveler
// Format is the format string with %placeholder% tokens.
Format string
// TimeLayout is the Go time layout used for the %time% placeholder.
// Defaults to [time.RFC3339] when empty.
TimeLayout string
// LineEnding is appended after each formatted record. Defaults to "\n".
// Set to a non-nil pointer to an empty string to suppress the line ending.
LineEnding *string
}
FormatHandlerOptions configures a FormatHandler.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log implements the Logger interface, dispatching named loggers to per-channel configurations when available, falling back to the base logger.
func NewLogger ¶
func NewLogger(channels ChannelConfig, base *slog.Logger) *Log
NewLogger creates a new Log with the given channel overrides and base logger.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin manages the slog-based logger.
func (*Plugin) ServiceLogger ¶
ServiceLogger returns a logger dedicated to the specific channel.
type RawHandler ¶
type RawHandler struct {
// contains filtered or unexported fields
}
RawHandler is an slog.Handler that outputs only the log message followed by a newline. Structured attributes and groups are discarded. This is used for the "raw" logger mode where callers want plain, undecorated output.
func NewRawHandler ¶
func NewRawHandler(w io.Writer, level slog.Leveler) *RawHandler
NewRawHandler returns a RawHandler writing to w. Only records at or above the given level are emitted.