| 1 |
//go:build go1.21 |
| 2 |
|
| 3 |
/* |
| 4 |
Copyright 2023 The logr Authors. |
| 5 |
|
| 6 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
you may not use this file except in compliance with the License. |
| 8 |
You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, software |
| 13 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
See the License for the specific language governing permissions and |
| 16 |
limitations under the License. |
| 17 |
*/ |
| 18 |
|
| 19 |
// Package slogr enables usage of a slog.Handler with logr.Logger as front-end |
| 20 |
// API and of a logr.LogSink through the slog.Handler and thus slog.Logger |
| 21 |
// APIs. |
| 22 |
// |
| 23 |
// See the README in the top-level [./logr] package for a discussion of |
| 24 |
// interoperability. |
| 25 |
// |
| 26 |
// Deprecated: use the main logr package instead. |
| 27 |
package slogr |
| 28 |
|
| 29 |
import ( |
| 30 |
"log/slog" |
| 31 |
|
| 32 |
"github.com/go-logr/logr" |
| 33 |
) |
| 34 |
|
| 35 |
// NewLogr returns a logr.Logger which writes to the slog.Handler. |
| 36 |
// |
| 37 |
// Deprecated: use [logr.FromSlogHandler] instead. |
| 38 |
func NewLogr(handler slog.Handler) logr.Logger { |
| 39 |
return logr.FromSlogHandler(handler) |
| 40 |
} |
| 41 |
|
| 42 |
// NewSlogHandler returns a slog.Handler which writes to the same sink as the logr.Logger. |
| 43 |
// |
| 44 |
// Deprecated: use [logr.ToSlogHandler] instead. |
| 45 |
func NewSlogHandler(logger logr.Logger) slog.Handler { |
| 46 |
return logr.ToSlogHandler(logger) |
| 47 |
} |
| 48 |
|
| 49 |
// ToSlogHandler returns a slog.Handler which writes to the same sink as the logr.Logger. |
| 50 |
// |
| 51 |
// Deprecated: use [logr.ToSlogHandler] instead. |
| 52 |
func ToSlogHandler(logger logr.Logger) slog.Handler { |
| 53 |
return logr.ToSlogHandler(logger) |
| 54 |
} |
| 55 |
|
| 56 |
// SlogSink is an optional interface that a LogSink can implement to support |
| 57 |
// logging through the slog.Logger or slog.Handler APIs better. |
| 58 |
// |
| 59 |
// Deprecated: use [logr.SlogSink] instead. |
| 60 |
type SlogSink = logr.SlogSink |