Documentation ¶
Index ¶
- Variables
- func NewDefaultDebugPrinter(level int) pterm.PrefixPrinter
- type PtermSink
- func (s PtermSink) Enabled(level int) bool
- func (s PtermSink) Error(err error, msg string, kvs ...interface{})
- func (s PtermSink) Info(level int, msg string, kvs ...interface{})
- func (s PtermSink) Init(_ logr.RuntimeInfo)
- func (s PtermSink) Name() string
- func (s *PtermSink) SetLevelEnabled(level int, enabled bool) *PtermSink
- func (s *PtermSink) SetLevelPrinter(level int, printer pterm.PrefixPrinter) *PtermSink
- func (s *PtermSink) SetOutput(output io.Writer) *PtermSink
- func (s PtermSink) WithName(name string) logr.LogSink
- func (s PtermSink) WithOutput(output io.Writer) *PtermSink
- func (s PtermSink) WithValues(kvs ...interface{}) logr.LogSink
Constants ¶
This section is empty.
Variables ¶
var DefaultErrorPrinter = *pterm.Error.WithPrefix(pterm.Prefix{Text: " ERROR ", Style: pterm.Error.Prefix.Style}).WithShowLineNumber(true).WithLineNumberOffset(4)
DefaultErrorPrinter is the default pterm.PrefixPrinter for the error level.
var DefaultFormatter = func(msg string, keysAndValues map[string]interface{}) string { if len(keysAndValues) <= 0 { return msg } pairs := make([]string, 0) for k, v := range keysAndValues { pairs = append(pairs, fmt.Sprintf("%s=\"%+v\"", k, v)) } msg = fmt.Sprintf("%s %s", msg, pterm.FgGray.Sprint("(", strings.Join(pairs, " "), ")")) return msg }
DefaultFormatter returns a string that looks as following (with colored key/values):
- message
- message (key="value" foo="bar")
var DefaultLevelPrinters = map[int]pterm.PrefixPrinter{ 0: *pterm.Info.WithPrefix(pterm.Prefix{Text: DefaultPrefixFormatter(0), Style: pterm.Info.Prefix.Style}), 1: NewDefaultDebugPrinter(1), }
DefaultLevelPrinters contains the default pterm.PrefixPrinter for a specific log levels.
var DefaultPrefixFormatter = func(level int) string { if level == 0 { return " INFO " } return fmt.Sprintf(" DBUG/%d ", level) }
DefaultPrefixFormatter returns the prefix text for the given log level for all Info messages.
var ScopeSeparator = ":"
ScopeSeparator delimits logger names.
Functions ¶
func NewDefaultDebugPrinter ¶ added in v0.7.0
func NewDefaultDebugPrinter(level int) pterm.PrefixPrinter
NewDefaultDebugPrinter returns a new pterm.PrefixPrinter with a pterm.Prefix that contains the log level.
Types ¶
type PtermSink ¶
type PtermSink struct { // LevelPrinters maps a pterm.PrefixPrinter to each supported log level. LevelPrinters map[int]pterm.PrefixPrinter // LevelEnabled enables or disables logging for the supported log levels. LevelEnabled map[int]bool // ErrorPrinter is the instance that formats and styles error messages. ErrorPrinter pterm.PrefixPrinter // contains filtered or unexported fields }
PtermSink implements logr.LogSink.
func NewPtermSink ¶
func NewPtermSink() PtermSink
NewPtermSink returns a new logr.LogSink instance where messages are being printed with pterm.PrefixPrinter. PtermSink.LevelPrinters and PtermSink.ErrorPrinter are initialized with DefaultLevelPrinters resp. pterm.Error.
func (PtermSink) Enabled ¶
Enabled implements logr.LogSink. It will return true if LevelEnabled has a key with the level and a value "true"
func (PtermSink) Error ¶
Error implements logr.LogSink. The given err is appended to the keys and values array with the "error" key, but only if err is non-nil.
func (*PtermSink) SetLevelEnabled ¶ added in v0.5.0
SetLevelEnabled explicitly enables or disables a logging level.
func (*PtermSink) SetLevelPrinter ¶ added in v0.7.0
func (s *PtermSink) SetLevelPrinter(level int, printer pterm.PrefixPrinter) *PtermSink
SetLevelPrinter sets the printer for the given logging level. Does not enable the given log level though.
func (*PtermSink) SetOutput ¶ added in v0.3.0
SetOutput is a convenience func that sets the new writer directly in pterm.PrefixPrinter. The difference to WithOutput is that setting the output on this instance also affects other log sinks that were created on the current state of s.
func (PtermSink) WithName ¶
WithName implements logr.LogSink. It returns a new logr.Logger instance that copies the pterm.PrefixPrinter from previous instance, but modifies the Scope property of the prefix printer. The value of the name is joined with the existing name, delimited by ScopeSeparator.
func (PtermSink) WithOutput ¶ added in v0.3.0
WithOutput returns a new sink that writes log messages to the given output. The difference to SetOutput is that this method doesn't alter the existing sink.
func (PtermSink) WithValues ¶
WithValues implements logr.LogSink. It returns a new logr.Logger instance that is pre-configured with given keys and values.