Documentation
¶
Overview ¶
Package log provides logging functionalities
Index ¶
- Constants
- func Error(err error, msg string, kvs ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(err error, msg string, kvs ...interface{})
- func GetLogTypeIndicator(logType LogType) string
- func Info(msg string, kvs ...interface{})
- func Infof(format string, args ...interface{})
- func Outputf(format string, args ...interface{})
- func QuietMode(quiet bool)
- func SetAuditLog(fileName string)
- func SetFile(fileName string)
- func SetStderr(writer io.Writer)
- func SetStdout(writer io.Writer)
- func SetVerbosity(verbosity int32)
- func ShowTimestamp(show bool)
- func Success(msg string, kvs ...interface{})
- func Successf(format string, args ...interface{})
- func Warning(msg string, kvs ...interface{})
- func Warningf(format string, args ...interface{})
- type LogType
- type LoggerImpl
- type Writer
Constants ¶
const (
EnvTanzuCLILogLevel = "TANZU_CLI_LOG_LEVEL"
)
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a error message with the given key/value pairs as context.
func Fatal ¶
Fatal logs a fatal message with the given key/value pairs as context and returns with os.Exit(1)
func GetLogTypeIndicator ¶ added in v1.2.0
func Info ¶
func Info(msg string, kvs ...interface{})
Info logs a non-error message with the given key/value pairs as context.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a non-error message with the given key/value pairs as context.
func QuietMode ¶
func QuietMode(quiet bool)
QuietMode sets the logging mode to quiet If this mode is set, writer will not write anything to stderr
func SetAuditLog ¶
func SetAuditLog(fileName string)
SetAuditLog sets the log file that should capture all logging activity. This file will contain all logging regardless of set verbosity level.
func SetFile ¶
func SetFile(fileName string)
SetFile sets the logFile to writer if the non-empty file name is used, writer will also write the logs to this file
func SetVerbosity ¶
func SetVerbosity(verbosity int32)
SetVerbosity sets verbosity level and also updates default verbosity level
func Success ¶
func Success(msg string, kvs ...interface{})
Success logs a success messages with the given key/value pairs as context.
func Successf ¶
func Successf(format string, args ...interface{})
Successf logs a success messages with the given message format with format specifier and arguments.
Types ¶
type LoggerImpl ¶
type LoggerImpl interface {
// Enabled tests whether this Logger is enabled. For example, commandline
// flags might be used to set the logging verbosity and disable some info
// logs.
Enabled() bool
// Info logs a non-error message with the given key/value pairs as context.
//
// The msg argument should be used to add some constant description to
// the log line. The key/value pairs can then be used to add additional
// variable information. The key/value pairs should alternate string
// keys and arbitrary values.
Info(msg string, keysAndValues ...interface{})
// Error logs an error, with the given message and key/value pairs as context.
// It functions similarly to calling Info with the "error" named value, but may
// have unique behavior, and should be preferred for logging errors (see the
// package documentations for more information).
//
// The msg field should be used to add context to any underlying error,
// while the err field should be used to attach the actual error that
// triggered this log line, if present.
Error(err error, msg string, keysAndValues ...interface{})
// V returns an Logger value for a specific verbosity level, relative to
// this Logger. In other words, V values are additive. V higher verbosity
// level means a log message is less important. It's illegal to pass a log
// level less than zero.
V(level int) LoggerImpl
// WithValues adds some key-value pairs of context to a logger.
// See Info for documentation on how key/value pairs work.
WithValues(keysAndValues ...interface{}) LoggerImpl
// WithName adds a new element to the logger's name.
// Successive calls with WithName continue to append
// suffixes to the logger's name. It's strongly recommended
// that name segments contain only letters, digits, and hyphens
// (see the package documentation for more information).
WithName(name string) LoggerImpl
// Infof logs a non-error messages with the given message format with format specifier and arguments.
Infof(format string, args ...interface{})
// Errorf logs a error message with the given key/value pairs as context.
Errorf(format string, args ...interface{})
// Warning logs a warning messages with the given key/value pairs as context.
Warning(msg string, kvs ...interface{})
// Warningf logs a warning messages with the given message format with format specifier and arguments.
Warningf(format string, args ...interface{})
// Success logs a success messages with the given key/value pairs as context.
Success(msg string, kvs ...interface{})
// Successf logs a success messages with the given message format with format specifier and arguments.
Successf(format string, args ...interface{})
// Fatal logs a fatal message with the given key/value pairs as context and returns with os.Exit(1)
Fatal(err error, msg string, kvs ...interface{})
// Print logs a message of generic type
Print(msg string, err error, logType string, kvs ...interface{})
// Output writes a message to stdout
Outputf(msg string, kvs ...interface{})
// SetThreshold implements a New Option that allows to set the threshold level for a logger.
// The logger will write only log messages with a level/V(x) equal or higher to the threshold.
SetThreshold(threshold *int32)
// Clone creates cloned copy of the logger
Clone() LoggerImpl
// CloneWithLevel creates cloned copy of the logger with updated log level
CloneWithLevel(level int) LoggerImpl
// WithCallDepth implements a New Option that allows to set the callDepth level for a logger.
WithCallDepth(callDepth int) LoggerImpl
}
LoggerImpl represents the ability to log messages, both errors and not.
func WithName ¶
func WithName(name string) LoggerImpl
WithName adds a new element to the logger's name.
func WithValues ¶
func WithValues(kvList ...interface{}) LoggerImpl
WithValues adds some key-value pairs of context to a logger.
type Writer ¶
type Writer interface {
// Write writes message to stdout/stderr, logfile and sends to the channel if channel is set
//
// header is message header to append as a message prefix
// msg is actual message to write
// logEnabled is used to decide whether to write this message to stdout/stderr or not
// logVerbosity is used to decide which message to write for different output types
// logType used to decide should write to stdout or stderr
Write(header []byte, msg []byte, logEnabled bool, logVerbosity int32, logType string) (n int, err error)
// SetFile sets the logFile to writer
// if the non-empty file name is used, writer will also
// write the logs to this file
SetFile(fileName string)
// SetAuditLog sets the log file that should capture all logging activity. This
// file will contain all logging regardless of set verbosity level.
SetAuditLog(fileName string)
// QuietMode sets the logging mode to quiet
// If this mode is set, writer will not write anything to stderr
QuietMode(quiet bool)
// ShowTimestamp shows timestamp along with log
ShowTimestamp(show bool)
// SetVerbosity sets verbosity level and also updates default verbosity level
SetVerbosity(verbosity int32)
// SetStdout overrides stdout
SetStdout(w io.Writer)
// SetStderr overrides stderr
SetStderr(w io.Writer)
}
Writer defines methods to write and configure tkg writer