diff options
author | 2024-01-15 14:08:07 +0100 | |
---|---|---|
committer | 2024-01-15 14:08:07 +0100 | |
commit | 6433a505820cfeb43990a3453a0ed8b24e432b7d (patch) | |
tree | 3f968a63d6a77991df95fde88ee0f08727f26eb6 /vendor/github.com/go-logr/logr/context_noslog.go | |
parent | [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.12 to 2.20.14 (#2530) (diff) | |
download | gotosocial-6433a505820cfeb43990a3453a0ed8b24e432b7d.tar.xz |
[chore] update bun + extras v1.1.16 -> v1.1.17 (#2534)
Diffstat (limited to 'vendor/github.com/go-logr/logr/context_noslog.go')
-rw-r--r-- | vendor/github.com/go-logr/logr/context_noslog.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/go-logr/logr/context_noslog.go b/vendor/github.com/go-logr/logr/context_noslog.go new file mode 100644 index 000000000..f012f9a18 --- /dev/null +++ b/vendor/github.com/go-logr/logr/context_noslog.go @@ -0,0 +1,49 @@ +//go:build !go1.21 +// +build !go1.21 + +/* +Copyright 2019 The logr Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logr + +import ( + "context" +) + +// FromContext returns a Logger from ctx or an error if no Logger is found. +func FromContext(ctx context.Context) (Logger, error) { + if v, ok := ctx.Value(contextKey{}).(Logger); ok { + return v, nil + } + + return Logger{}, notFoundError{} +} + +// FromContextOrDiscard returns a Logger from ctx. If no Logger is found, this +// returns a Logger that discards all log messages. +func FromContextOrDiscard(ctx context.Context) Logger { + if v, ok := ctx.Value(contextKey{}).(Logger); ok { + return v + } + + return Discard() +} + +// NewContext returns a new Context, derived from ctx, which carries the +// provided Logger. +func NewContext(ctx context.Context, logger Logger) context.Context { + return context.WithValue(ctx, contextKey{}, logger) +} |