wrap

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

CI Go Report Card GoDoc

wrap

import "github.com/go-coldbrew/log/wrap"

Index

func ToSlogHandler

func ToSlogHandler(l log.Logger) slog.Handler

ToSlogHandler wraps a ColdBrew log.Logger as an slog.Handler.

Deprecated: With the slog-native architecture, use log.GetHandler() directly as it already implements slog.Handler with context field injection. This function is kept for backward compatibility with custom Logger implementations.

func ToSlogLogger

func ToSlogLogger(l log.Logger) *slog.Logger

ToSlogLogger wraps a ColdBrew log.Logger as an *slog.Logger.

Deprecated: With the slog-native architecture, the global slog.Logger is already configured via log.SetDefault. Use slog.Default() or slog.New(log.GetHandler()) instead.

Example

This example shows how to route slog calls through ColdBrew's logger. Third-party libraries using slog.Info() will flow through your ColdBrew logging pipeline (context fields, level overrides, interceptors).

package main

import (
	"context"
	"log/slog"

	"github.com/go-coldbrew/log"
	"github.com/go-coldbrew/log/wrap"
)

func main() {
	// Set up slog's default to route through ColdBrew
	sl := wrap.ToSlogLogger(log.GetLogger())
	slog.SetDefault(sl)

	// Now slog calls flow through ColdBrew's pipeline
	ctx := context.Background()
	slog.InfoContext(ctx, "request processed", "method", "GET", "status", 200)
}

Example (With Group)

This example shows how to use slog's WithGroup and With methods through the ColdBrew bridge.

package main

import (
	"context"

	"github.com/go-coldbrew/log"
	"github.com/go-coldbrew/log/wrap"
)

func main() {
	sl := wrap.ToSlogLogger(log.GetLogger())

	// Groups produce dot-separated keys (e.g., "request.method")
	reqLogger := sl.WithGroup("request").With("trace_id", "abc-123")

	ctx := context.Background()
	reqLogger.InfoContext(ctx, "handled", "method", "POST", "path", "/api/orders")
}

Generated by gomarkdoc

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSlogHandler deprecated added in v0.2.8

func ToSlogHandler(l log.Logger) slog.Handler

ToSlogHandler wraps a ColdBrew log.Logger as an slog.Handler.

Deprecated: With the slog-native architecture, use log.GetHandler() directly as it already implements slog.Handler with context field injection. This function is kept for backward compatibility with custom Logger implementations.

func ToSlogLogger deprecated added in v0.2.8

func ToSlogLogger(l log.Logger) *slog.Logger

ToSlogLogger wraps a ColdBrew log.Logger as an *slog.Logger.

Deprecated: With the slog-native architecture, the global slog.Logger is already configured via log.SetDefault. Use slog.Default() or slog.New(log.GetHandler()) instead.

Example

This example shows how to route slog calls through ColdBrew's logger. Third-party libraries using slog.Info() will flow through your ColdBrew logging pipeline (context fields, level overrides, interceptors).

package main

import (
	"context"
	"log/slog"

	"github.com/go-coldbrew/log"
	"github.com/go-coldbrew/log/wrap"
)

func main() {
	// Set up slog's default to route through ColdBrew
	sl := wrap.ToSlogLogger(log.GetLogger())
	slog.SetDefault(sl)

	// Now slog calls flow through ColdBrew's pipeline
	ctx := context.Background()
	slog.InfoContext(ctx, "request processed", "method", "GET", "status", 200)
}
Example (WithGroup)

This example shows how to use slog's WithGroup and With methods through the ColdBrew bridge.

package main

import (
	"context"

	"github.com/go-coldbrew/log"
	"github.com/go-coldbrew/log/wrap"
)

func main() {
	sl := wrap.ToSlogLogger(log.GetLogger())

	// Groups produce dot-separated keys (e.g., "request.method")
	reqLogger := sl.WithGroup("request").With("trace_id", "abc-123")

	ctx := context.Background()
	reqLogger.InfoContext(ctx, "handled", "method", "POST", "path", "/api/orders")
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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