log

package
v9.1.81+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLogQueueFull = errors.New("error: log queue full, dropping log message")

ErrLogQueueFull will return when the log queue is full

View Source
var ErrMissingValue = errors.New("(MISSING)")

ErrMissingValue is appended to keyvals slices with odd length to substitute the missing value.

View Source
var MaxStringValueLength = 1024 * 10 // ~10kb

MaxStringValueLength is the maximum size of a string value we will return before truncating

View Source
var (
	// TerminationLogPath is the path to the termination log if running inside a container
	TerminationLogPath = "/dev/termination-log"
)

Functions

func Debug

func Debug(logger Logger, msg string, kv ...interface{}) error

Debug log helper

func DeleteLogFile

func DeleteLogFile() error

DeleteLogFile will delete the log file

func Error

func Error(logger Logger, msg string, kv ...interface{}) error

Error log helper

func Fatal

func Fatal(logger Logger, msg string, kv ...interface{})

Fatal log helper

func Info

func Info(logger Logger, msg string, kv ...interface{}) error

Info log helper

func MaskKV

func MaskKV(k, v string) (string, bool)

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

func RegisterFlags(rootCmd *cobra.Command)

RegisterFlags will register the flags for logging

func Warn

func Warn(logger Logger, msg string, kv ...interface{}) error

Warn log helper

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

const (
	// InfoLevel will only log level and above (default)
	InfoLevel Level = 1 << iota
	// DebugLevel will log all messages
	DebugLevel
	// WarnLevel will only log warning and above
	WarnLevel
	// ErrorLevel will only log error and above
	ErrorLevel
	// NoneLevel will no log at all
	NoneLevel
)

func LevelFromString

func LevelFromString(level string) Level

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

func With(logger Logger, keyvals ...interface{}) Logger

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

type LoggerCloser interface {
	Logger
	Close() error
}

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

type WithLogOptions func(logger Logger) Logger

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL