Documentation ¶
Index ¶
- func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error
- func ToAttrs(data map[string]any) []slog.Attr
- func ToLeveler(level string) slog.Leveler
- type ChannelConfig
- type Config
- type ConsoleHandler
- type HandlerOptions
- type HandlerSyncer
- type Log
- type Logger
- type Sink
- type WriteSyncer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterSink ¶
RegisterSink registers a user-supplied factory for all sinks with a particular scheme.
All schemes must be ASCII, valid under section 0.1 of RFC 3986 (https://tools.ietf.org/html/rfc3983#section-3.1), and must not already have a factory registered. Zap automatically registers a factory for the "file" scheme.
Types ¶
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 { // When AddSource is true, the handler adds a ("source", "file:line") // attribute to the output indicating the source code position of the log // statement. AddSource is false by default to skip the cost of computing // this information. AddSource bool `mapstructure:"add_source"` // Level is the minimum enabled logging level. Level string `mapstructure:"level"` // Encoding sets the logger's encoding. Init values are "json", "text" and "console" Encoding string `mapstructure:"encoding"` // Output is a list of URLs or file paths to write logging output to. // See Open for details. OutputPaths []string `mapstructure:"output_paths"` Attrs map[string]any `mapstructure:"attributes"` }
func (*Config) OpenSinks ¶
func (cfg *Config) OpenSinks() (WriteSyncer, error)
func (*Config) Opts ¶
func (cfg *Config) Opts() HandlerOptions
type ConsoleHandler ¶
type ConsoleHandler struct {
// contains filtered or unexported fields
}
func NewConsoleHandler ¶
func NewConsoleHandler(opts slog.HandlerOptions, w io.Writer, attrs ...slog.Attr) *ConsoleHandler
type HandlerOptions ¶
type HandlerOptions struct {
slog.HandlerOptions
}
func (HandlerOptions) NewConsoleHandler ¶
func (opts HandlerOptions) NewConsoleHandler(w io.Writer) *ConsoleHandler
func (HandlerOptions) NewHandler ¶
type HandlerSyncer ¶
type HandlerSyncer interface {
Sync() error
}
type Sink ¶
type Sink interface { WriteSyncer io.Closer }
type WriteSyncer ¶
func AddSync ¶
func AddSync(w io.Writer) WriteSyncer
func CombineWriteSyncers ¶
func CombineWriteSyncers(writers ...WriteSyncer) WriteSyncer
CombineWriteSyncers is a utility that combines multiple WriteSyncers into a single, locked WriteSyncer. If no inputs are supplied, it returns a no-op WriteSyncer.
It's provided purely as a convenience; the result is no different from using zapcore.NewMultiWriteSyncer and zapcore.Lock individually.
func Lock ¶
func Lock(ws WriteSyncer) WriteSyncer
Lock wraps a WriteSyncer in a mutex to make it safe for concurrent use. In particular, *os.Files must be locked before use.
func NewMultiWriteSyncer ¶
func NewMultiWriteSyncer(ws ...WriteSyncer) WriteSyncer
func Open ¶
func Open(paths ...string) (WriteSyncer, func(), error)
Open is a high-level wrapper that takes a variadic number of URLs, opens or creates each of the specified resources, and combines them into a locked WriteSyncer. It also returns any error encountered and a function to close any opened files.
Passing no URLs returns a no-op WriteSyncer. Zap handles URLs without a scheme and URLs with the "file" scheme. Third-party code may register factories for other schemes using RegisterSink.
URLs with the "file" scheme must use absolute paths on the local filesystem. No user, password, port, fragments, or query parameters are allowed, and the hostname must be empty or "localhost".
Since it's common to write logs to the local filesystem, URLs without a scheme (e.g., "/var/log/foo.log") are treated as local file paths. Without a scheme, the special paths "stdout" and "stderr" are interpreted as os.Stdout and os.Stderr. When specified without a scheme, relative file paths also work.