package stdr
Import Path
github.com/go-logr/stdr (on go.dev)
Dependency Relation
imports 4 packages, and imported by one package
Involved Source Files
Package stdr implements github.com/go-logr/logr.Logger in terms of
Go's standard log package.
Code Examples
package main
import (
"errors"
"log"
"os"
"github.com/go-logr/stdr"
)
var errSome = errors.New("some error")
func newStdLogger(flags int) stdr.StdLogger {
return log.New(os.Stdout, "", flags)
}
func main() {
log := stdr.New(newStdLogger(log.Lshortfile))
log.Info("info message with default options")
log.Error(errSome, "error message with default options")
log.Info("invalid key", 42, "answer")
log.Info("missing value", "answer")
}
package main
import (
"log"
"os"
"github.com/go-logr/stdr"
)
func newStdLogger(flags int) stdr.StdLogger {
return log.New(os.Stdout, "", flags)
}
func main() {
log := stdr.NewWithOptions(newStdLogger(0), stdr.Options{LogCaller: stdr.All})
log.Info("with LogCaller=All")
}
package main
import (
"log"
"os"
"github.com/go-logr/stdr"
)
func newStdLogger(flags int) stdr.StdLogger {
return log.New(os.Stdout, "", flags)
}
func main() {
log := stdr.New(newStdLogger(0))
log.WithName("hello").WithName("world").Info("thanks for the fish")
}
Package-Level Type Names (total 4)
MessageClass indicates which category or categories of messages to consider.
const All
const Error
const Info
const None
Options carries parameters which influence the way logs are generated.
Depth biases the assumed number of call frames to the "true" caller.
This is useful when the calling code calls a function which then calls
stdr (e.g. a logging shim to another API). Values less than zero will
be treated as zero.
LogCaller tells stdr to add a "caller" key to some or all log lines.
Go's log package has options to log this natively, too.
func NewWithOptions(std StdLogger, opts Options) logr.Logger
StdLogger is the subset of the Go stdlib log.Logger API that is needed for
this adapter.
Output is the same as log.Output and log.Logger.Output.
*log.Logger
func Underlier.GetUnderlying() StdLogger
func New(std StdLogger) logr.Logger
func NewWithOptions(std StdLogger, opts Options) logr.Logger
Underlier exposes access to the underlying logging implementation. Since
callers only have a logr.Logger, they have to know which implementation is
in use, so this interface is less of an abstraction and more of way to test
type conversion.
( Underlier) GetUnderlying() StdLogger
Package-Level Functions (total 3)
New returns a logr.Logger which is implemented by Go's standard log package,
or something like it. If std is nil, this will use a default logger
instead.
Example: stdr.New(log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile)))
NewWithOptions returns a logr.Logger which is implemented by Go's standard
log package, or something like it. See New for details.
SetVerbosity sets the global level against which all info logs will be
compared. If this is greater than or equal to the "V" of the logger, the
message will be logged. A higher value here means more logs will be written.
The previous verbosity value is returned. This is not concurrent-safe -
callers must be sure to call it from only one goroutine.
Package-Level Constants (total 4)
All considers all message classes.
Error only considers error messages.
Info only considers info messages.
None ignores all message classes.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |