Documentation ¶
Overview ¶
Package sloggy provides a fairly straightforward slog.Handler implementation. It is feature-complete per observed slog.JSONHandler behavior.
This was an initial, naive attempt to write a "better" handler (because hubris). It is the second "feature complete" handler after slog.JSONHandler (which is admittedly used as a "default behavior" model throughout the verification suite). A user could switch between the two handlers and be reasonably confident that the log output would be the same.
Performance not as good as slog.JSONHandler. The only planned performance enhancement was to use prefix/postfix byte arrays, otherwise this was a green field build with performance left until later. The flash handler, originally a copy of this one, has been tweaked for performance.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides a fairly straightforward, feature-complete slog.Handler implementation.
Example ¶
var buff bytes.Buffer logger := slog.New(NewHandler(&buff, nil)) logger.Info("hello", "count", math.Pi) var logMap map[string]any _ = json.Unmarshal(buff.Bytes(), &logMap) fmt.Printf("%s %6.5f\n", logMap["msg"], logMap["count"].(float64))
Output: hello 3.14159
func NewHandler ¶
func NewHandler(writer io.Writer, options *slog.HandlerOptions) *Handler
NewHandler returns a new sloggy handler with the specified output writer and slog.HandlerOptions. If the options argument is nil it will be set to a level of slog.LevelInfo and nothing else.