Documentation ¶
Index ¶
- Variables
- func Debug(logger Logger, msg string, kv ...interface{}) error
- func DeleteLogFile() error
- func Error(logger Logger, msg string, kv ...interface{}) error
- func Fatal(logger Logger, msg string, kv ...interface{})
- func Info(logger Logger, msg string, kv ...interface{}) error
- func MaskKV(k, v string) (string, bool)
- func NewRandomLogPath() string
- func RegisterFlags(rootCmd *cobra.Command)
- func Warn(logger Logger, msg string, kv ...interface{}) error
- type BackgroundLoggerCallback
- type ColorTheme
- type Level
- type Logger
- type LoggerCloser
- type OutputFormat
- type WithLogOptions
- type WrappedLogCloser
Constants ¶
This section is empty.
Variables ¶
var ErrLogQueueFull = errors.New("error: log queue full, dropping log message")
ErrLogQueueFull will return when the log queue is full
var ErrMissingValue = errors.New("(MISSING)")
ErrMissingValue is appended to keyvals slices with odd length to substitute the missing value.
var MaxStringValueLength = 1024 * 10 // ~10kb
MaxStringValueLength is the maximum size of a string value we will return before truncating
var (
// TerminationLogPath is the path to the termination log if running inside a container
TerminationLogPath = "/dev/termination-log"
)
Functions ¶
func MaskKV ¶
MaskKV will mask a map of strings to strings and that and weather or not it changed anything
func NewRandomLogPath ¶
func NewRandomLogPath() string
NewRandomLogPath will define a random log path in the env, it does not create a logfile, just a path.
func RegisterFlags ¶
RegisterFlags will register the flags for logging
Types ¶
type BackgroundLoggerCallback ¶
type BackgroundLoggerCallback func(fn string)
BackgroundLoggerCallback is a callback function that will get invoked when the log needs to be fetched
type ColorTheme ¶
type ColorTheme byte
ColorTheme is the logging color theme
const ( // DarkLogColorTheme is the default color theme for console logging (if enabled) DarkLogColorTheme ColorTheme = 1 << iota // LightLogColorTheme is for consoles that are light (vs dark) LightLogColorTheme // NoColorTheme will turn off console colors NoColorTheme )
type Level ¶
type Level byte
Level is the minimum logging level
func LevelFromString ¶
LevelFromString will return a LogLevel const from a named string
type Logger ¶
type Logger interface {
Log(keyvals ...interface{}) error
}
Logger is the fundamental interface for all log operations. Log creates a log event from keyvals, a variadic sequence of alternating keys and values. Implementations must be safe for concurrent use by multiple goroutines. In particular, any implementation of Logger that appends to keyvals or modifies or retains any of its elements must make a copy first.
func With ¶
With returns a new contextual logger with keyvals prepended to those passed to calls to Log. If logger is also a contextual logger created by With or WithPrefix, keyvals is appended to the existing context.
The returned Logger replaces all value elements (odd indexes) containing a Valuer with their generated value for each call to its Log method.
type LoggerCloser ¶
LoggerCloser returns a logger which implements a Close interface
func NewCommandLogger ¶
func NewCommandLogger(cmd *cobra.Command, opts ...WithLogOptions) LoggerCloser
NewCommandLogger returns a new Logger for a given command
func NewLogger ¶
func NewLogger(writer io.Writer, format OutputFormat, theme ColorTheme, minLevel Level, pkg string, opts ...WithLogOptions) LoggerCloser
NewLogger will create a new logger
func NewNoOpTestLogger ¶
func NewNoOpTestLogger() LoggerCloser
NewNoOpTestLogger is a test logger that doesn't log at all
type OutputFormat ¶
type OutputFormat byte
OutputFormat is the logging output format
const ( // JSONLogFormat will output JSON formatted logs JSONLogFormat OutputFormat = 1 << iota // LogFmtLogFormat will output logfmt formatted logs LogFmtLogFormat // ConsoleLogFormat will output logfmt colored logs to console ConsoleLogFormat )
type WithLogOptions ¶
WithLogOptions is a callback for customizing the logger event further before returning
func WithBackgroundLogger ¶
func WithBackgroundLogger(callback BackgroundLoggerCallback) WithLogOptions
WithBackgroundLogger will return a logger which will collect log file and call the callback upon exit with the name of the logfile for further processing when the process is completed
func WithCrashLogger ¶
func WithCrashLogger() WithLogOptions
WithCrashLogger will tell the logger to create a logfile and log to it, in the event of a crash it will send the logfile to our analytics api. At the end of execution the log file will be deleted
func WithDefaultTimestampLogOption ¶
func WithDefaultTimestampLogOption(layout ...string) WithLogOptions
WithDefaultTimestampLogOption will add the timestamp using layout format provided. If not provided, use time.StampMilli
type WrappedLogCloser ¶
type WrappedLogCloser struct {
// contains filtered or unexported fields
}
WrappedLogCloser wraps a logger and its delegate
func NewWrappedLogCloser ¶
func NewWrappedLogCloser(logger Logger, delegate Logger) *WrappedLogCloser
NewWrappedLogCloser returns a new instance of WrappedLogCloser
func (*WrappedLogCloser) Close ¶
func (l *WrappedLogCloser) Close() error
Close will close the underlying channel
func (*WrappedLogCloser) Log ¶
func (l *WrappedLogCloser) Log(keyvals ...interface{}) error
Log will send logs to delegate