sloglambda

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2024 License: Unlicense Imports: 10 Imported by: 1

README

slog-lambda

current codecov Doc License

AWS Lambda slog.Handler

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(w io.Writer, options ...Option) *Handler
Example
package main

import (
	"log/slog"
	"os"

	sloglambda "github.com/maddiesch/slog-lambda"
)

func main() {
	handler := sloglambda.NewHandler(os.Stdout, sloglambda.WithJSON(), sloglambda.WithoutTime())
	logger := slog.New(handler)

	slog.SetDefault(logger)

	slog.Info("Hello, world!")
}
Output:

{"level":"INFO","msg":"Hello, world!","record":{"functionName":"test-function","functionVersion":"$LATEST"},"type":"app.log"}

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, record slog.Record) error

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attr []slog.Attr) slog.Handler

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

type Option

type Option func(*Handler)

func WithJSON

func WithJSON() Option

func WithLevel

func WithLevel(level slog.Level) Option

func WithSource

func WithSource() Option

func WithText

func WithText() Option

func WithType

func WithType(logType string) Option

func WithoutTime

func WithoutTime() Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL