import "github.com/asifjalil/stdlogr"
Package stdlogr implements github.com/go-logr/logr.Logger in terms of Go's standard log package.
Copied from https://github.com/go-logr/stdr
- func New(std StdLogger) logr.Logger
- func SetVerbosity(v int) int
- type DefaultFormatter
- type Entry
- type Formatter
- type Logger
- func (l Logger) Enabled() bool
- func (l Logger) Error(err error, msg string, kvList ...interface{})
- func (l Logger) Info(msg string, kvList ...interface{})
- func (l Logger) V(level int) logr.InfoLogger
- func (l Logger) WithName(name string) logr.Logger
- func (l Logger) WithValues(kvList ...interface{}) logr.Logger
- type StdLogger
func New(std StdLogger) logr.Logger
New returns a logr.Logger which is implemented by Go's standard log package.
Example: stdr.New(log.New(os.Stderr, "", log.LstdFlags))
You can also just instantiate your own:
var log = stdr.Logger{
Std: log.New(os.Stderr, "", log.LstdFlags),
Depth: 0
Formatter: stdr.DefaultFormatter{},
}
func SetVerbosity(v int) int
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.
SetVerbosity is concurrent-safe.
type DefaultFormatter struct {
// TimestampFormat sets the format used to print log timestamp.
// If TimestampFormat is set, make sure timestamp flags are off
// for the std. logger. Otherwise there will be duplicate timestamp
// in the output.
TimestampFormat string
// ForceQuote true quotes all fieldKeys and fieldValues using %q.
ForceQuote bool
// HideKeys true will show [fieldValue] instead of [fieldKey=fieldValue]
HideKeys bool
}
func (f DefaultFormatter) Format(e Entry) string
Format a log entry.
type Entry struct {
// Err is an error being logged using `logr Error(err error ...)` method.
Err error
// Name is logger name. It constists of a series of name "segments"
// added by successive calls to `logr WithName(name string)` method.
Name string
// Verbosity represents how little a log matters.
// Level zero, the default, matters most. Increasing levels matter less and less.
// Verbosity is specified using `logr V(level int)` method.
Verbosity int
// Message consists of a constant message attached to the the log line.
// This should generally be a simple description of what's occuring,
// and should never be a format string.
// Message is spcified using `logr Info` method and `logr Error` method.
Message string
// KeyAndValues where keys are arbitrary strings, while values may be any Go value.
// KeyAndValues specified using `logr WithValues`, `logr Info`, and `logr Error` method.
KeysAndValues []interface{}
}
Entry is a log entry.
It is used by Formatter
to log format output.
type Formatter interface {
Format(Entry) string
}
Formatter formats a log entry Entry.
type Logger struct {
Std StdLogger
// DepthOffset biases the assumed number of call frames to the "true"
// caller. This is useful when the calling code calls a function which then
// calls glogr (e.g. a logging shim to another API). Values less than zero
// will be treated as zero.
Depth int
// All log entries pass through the formatter before logged to Out. The
// included formatter is `DefaultFormatter`.
// You can easily implement your Formatter implements the `Formatter` interface, see the
// or included formatters for example.
Formatter Formatter
// contains filtered or unexported fields
}
func (l Logger) Enabled() bool
func (l Logger) Error(err error, msg string, kvList ...interface{})
func (l Logger) Info(msg string, kvList ...interface{})
func (l Logger) V(level int) logr.InfoLogger
func (l Logger) WithName(name string) logr.Logger
WithName returns a new logr.Logger with the specified name appended. stdr uses '/' characters to separate name elements. Callers should not pass '/' in the provided name string, but this library does not actually enforce that.
func (Logger) WithValues
func (l Logger) WithValues(kvList ...interface{}) logr.Logger
type StdLogger interface {
// Output is the same as log.Output and log.Logger.Output.
Output(calldepth int, logline string) error
}
StdLogger is the subset of the Go stdlib log.Logger API that is needed for this adapter.
Generated by godoc2md