Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateLogger ¶
func GetLogger ¶ added in v1.2.0
GetLogger retrieves a logger instance from the given context.
This function attempts to extract a logger from the context using the key "logger". If the key is not present or the value is not of type *slog.Logger, it falls back to returning the default logger provided by slog.
Usage:
- To use this function effectively, ensure that the context has a logger stored using context.WithValue, with the key "logger" and a value of type *slog.Logger.
- If no logger is found in the context, slog.Default() is returned.
Parameters: - ctx (context.Context): The context from which the logger will be extracted.
Returns: - *slog.Logger: The logger instance extracted from the context or the default logger.
Example: ```go logger := slog.New(slog.WithLevel(slog.LevelInfo)) ctx := context.WithValue(context.Background(), "logger", logger) retrievedLogger := GetLogger(ctx) retrievedLogger.Info("Logger successfully retrieved!") ```
Types ¶
type GroupOrAttrs ¶ added in v1.2.0
type GroupOrAttrs struct {
// contains filtered or unexported fields
}
type PrettyHandler ¶ added in v1.2.0
func NewPrettyHandler ¶ added in v1.2.0
func NewPrettyHandler(out io.Writer, opts PrettyHandlerOptions) *PrettyHandler
type PrettyHandlerOptions ¶ added in v1.2.0
type PrettyHandlerOptions struct {
SlogOpts slog.HandlerOptions
}