powerslog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 4 Imported by: 1

README

Powerslog

Getting started

Requirements
  • Go 1.22+
Installation and usage
package main

import (
	"log/slog"
	"os"

	"github.com/unfunco/powerslog"
)

func main() {
	jsonHandler := slog.NewJSONHandler(os.Stdout, nil)
	powerslogHandler := powerslog.NewHandler(jsonHandler, nil)
	logger := slog.New(powerslogHandler)

	logger.Info("Hello, world!")
}

License

© 2024 Daniel Morris
Made available under the terms of the MIT License.

Documentation

Overview

Package powerslog provides a slog.Handler implementation designed for use with AWS Lambda functions and captures key fields from the Lambda context, it is intended to be functionally similar to the Powertools loggers for Python and TypeScript whilst remaining idiomatic for the Go programming language.

Index

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
}

Handler is a slog.Handler that writes Records that include key fields from an AWS Lambda context to an io.Writer.

func NewHandler

func NewHandler(handler slog.Handler) *Handler

NewHandler creates a Handler that writes to w, using the given options. It adds the service name and function name to the attributes of the log record during handler construction since these values are not going to change during the lifetime of the handler.

func (*Handler) Enabled

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

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.

func (*Handler) Handle

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

Handle implements the slog.Handler interface and handles the Record. It will only be called when Enabled returns true.

func (*Handler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

func (*Handler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

Directories

Path Synopsis
lambda module

Jump to

Keyboard shortcuts

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