Documentation
¶
Index ¶
- func EnrichRecordWithMetaData(ctx context.Context, r slog.Record) slog.Record
- func Fields(ctx context.Context) []slog.Attr
- func New() *slog.Logger
- func NewContextHandler(baseHandler slog.Handler) slog.Handler
- func NewWithConfig(cfg *Config) *slog.Logger
- func NewWithFile(filePath string, cfg *Config) (*slog.Logger, io.Closer, error)
- func WithFields(ctx context.Context, attrs ...slog.Attr) context.Context
- type Config
- type ContextHandler
- type TimeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New - a handy wrapper that configures the slog.Logger in a consistent fashion. Engineers should always default to using this constructor to ensure that they can take advantage of future global enhancements to our logging setup.
func NewWithConfig ¶ added in v1.35.0
NewWithConfig - a constructor that allows you to overwrite some of the core constructs within the Logger for your own nefarious purposes.
func NewWithFile ¶ added in v1.37.0
NewWithFile creates a logger writing to a file. Caller is responsible for closing the returned file. Should there be an error with the opening of the filePath this will gracefully degrade and provide a Stderr logger alongside an error. This allows the consumer to decide how they wish to proceed rather than outright blocking application startup.
func WithFields ¶
WithField - provides a way to inject more fields into a logger that is then persisted in the context. This is useful in situations where they need to employ canonical logging in order to limit the number of log lines that they emit.
Types ¶
type Config ¶
type Config struct {
// Writer - a lower level construct that allows
// engineers to have finer-grained control over
// how and where logs are written to file.
Writer io.Writer
// UseTextFormat - set this to true if you require
// text formatted logs.
UseTextFormat bool
// Clock - allows the consumer to provide their own
// TimeFunc that is used to provide the timestamp when
// emitting logs.
// The logger defaults to UTC to try and ensure
// consistency across our services.
Clock TimeFunc
// LogLevel - represents the minimum log level that
// should be output by the logger.
LogLevel slog.Level
}
Config holds the configuration for creating a new logger.