Documentation
¶
Index ¶
- Constants
- Variables
- type Encoder
- type JSONEncoder
- type Line
- type LineJSON
- type LineJSONDev
- type Sink
- func (s *Sink) Enabled(level int) bool
- func (s *Sink) Error(err error, msg string, keysAndValues ...interface{})
- func (s *Sink) GetVerbosity() int
- func (s *Sink) Info(level int, msg string, keysAndValues ...interface{})
- func (s *Sink) Init(info logr.RuntimeInfo)
- func (s *Sink) SetOutput(w io.Writer)
- func (s *Sink) SetVerbosity(v int)
- func (s *Sink) WithName(name string) logr.LogSink
- func (s *Sink) WithValues(keysAndValues ...interface{}) logr.LogSink
- type Verbosity
Constants ¶
const ( TimeStampKey = "_ts" FileLineKey = "_file:line" LevelKey = "_level" ComponentKey = "_component" MessageKey = "_message" ErrorKey = "_error" )
Keys used to log specific builtin fields
Variables ¶
var TimestampFunc = func() string { return time.Now().UTC().Format(time.RFC3339Nano) }
TimestampFunc returns a string formatted version of the current time. This should probably only be used with tests or if you want to change the default time formatting of the output logs.
Functions ¶
This section is empty.
Types ¶
type Line ¶
type Line struct { Timestamp string FileLine string Verbosity string Component string Message string Context map[string]interface{} }
Line orders log line fields
func (Line) MarshalJSON ¶
MarshalJSON implements custom marshaling for log line: (1) flattening context (2) support for developer mode
type LineJSON ¶
type LineJSON struct { Timestamp string `json:"_ts"` FileLine string `json:"-"` Verbosity string `json:"_level"` Component string `json:"_component"` Message string `json:"_message"` Context map[string]interface{} `json:"-"` }
LineJSON add json tags to Line struct (production logs)
type LineJSONDev ¶
type LineJSONDev struct { Timestamp string `json:"_ts"` FileLine string `json:"_file:line"` Verbosity string `json:"_level"` Component string `json:"_component"` Message string `json:"_message"` Context map[string]interface{} `json:"-"` }
LineJSONDev add json tags to Line struct (developer logs, enable using environment variable LOG_DEV)
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink writes logs to a specified output
func NewLogSink ¶
func NewLogSink(name string, w io.Writer, v Verbosity, e Encoder, keysAndValues ...interface{}) *Sink
NewLogSink creates a new logsink
func (*Sink) Enabled ¶
Enabled determines if a logger should record a log. If the log's verbosity is higher or equal to that the logger's level, the log is recorded. Otherwise, it is skipped.
func (*Sink) Error ¶
Error logs an error, with the given message and key/value pairs as context. Unlike Info, it bypasses the Enabled check. Logs will always be recorded from this method.
func (*Sink) Info ¶
Info logs a non-error message with the given key/value pairs as context. Info will check to see if the log is enabled for the logger's level before recording.
func (*Sink) Init ¶
func (s *Sink) Init(info logr.RuntimeInfo)
Init receives optional information about the logr library for LogSink implementations that need it.
func (*Sink) SetVerbosity ¶
SetVerbosity sets the log level allowed by the logsink
func (*Sink) WithValues ¶
WithValues clones the logsink and appends keysAndValues.
type Verbosity ¶
type Verbosity int
Verbosity is a level of verbosity to log between 0 and math.MaxInt32 However it is recommended to keep the numbers between 0 and 3
func (Verbosity) MarshalJSON ¶
MarshalJSON marshas JSON