Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wrapper for Middleware #11

Merged
merged 4 commits into from
Feb 27, 2025
Merged

Conversation

ArtARTs36
Copy link
Contributor

@ArtARTs36 ArtARTs36 commented Feb 24, 2025

This Pull Request adds wrapper from slog.Handler to slogx.Middleware

This will allow you to easy connect other popular extensions to slog e.g. slog-sentry, slog-nats and others that provide the slog.Handler interface.

Usage example:

package main

import (
	"os"

	slognats "github.com/samber/slog-nats"
	"github.com/cappuccinotm/slogx"
	"github.com/cappuccinotm/slogx/slogm"
	"log/slog"
)

func main() {
	h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
		AddSource: true,
		Level:     slog.LevelInfo,
	})

	logger := slog.New(slogx.Accumulator(slogx.NewChain(h,
		slogm.RequestID(),
		// ...
		slogx.HandlerAsMiddleware(slognats.Option{Level: slog.LevelDebug, EncodedConnection: ec, Sub}.NewNATSHandler()),
	)))

	logger.Info("some message")
}

This will allow you not to connect additional libraries like slog-multi unless absolutely necessary.

@ArtARTs36 ArtARTs36 requested a review from Semior001 as a code owner February 24, 2025 22:21
@ArtARTs36 ArtARTs36 changed the title feat: add wrappers for Middleware feat: add wrapper for Middleware Feb 24, 2025
Copy link
Member

@Semior001 Semior001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! A few minor things

Copy link
Member

@Semior001 Semior001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Semior001 Semior001 merged commit f6f9865 into cappuccinotm:master Feb 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants