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