log

package
v0.13.0-dev Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package log provides logging functionalities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(err error, msg string, kvs ...interface{})

Error logs an error message with the given key/value pairs as context.

func Fatal

func Fatal(err error, msg string, kvs ...interface{})

Fatal logs a fatal message with the given key/value pairs as context and returns with os.Exit(255)

func ForceWriteToStdErr

func ForceWriteToStdErr(msg []byte)

ForceWriteToStdErr writes to stdErr

func GetLogr

func GetLogr() logr.Logger

GetLogr logs a warning messages with the given message format with format specifier and arguments.

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 Outputf

func Outputf(format string, args ...interface{})

Outputf writes a message to stdout

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 SendProgressUpdate

func SendProgressUpdate(status, currentPhase string, totalPhases []string)

SendProgressUpdate sends the progress to the listening logChannel

func SetChannel

func SetChannel(channel chan<- []byte)

SetChannel sets the channel to writer if channel is set, writer will forward log messages to this log channel

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 UnsetStdoutStderr

func UnsetStdoutStderr()

UnsetStdoutStderr intercept the actual stdout and stderr this will ensure no other external library prints to stdout/stderr and use actual stdout/stderr through tkg writer only Note: Should not use this functions for normal cli commands like

tkg get regions, tkg set regions

As it will stop any libraries like table.pretty to print on stdout

func Warning

func Warning(msg string, kvs ...interface{})

Warning logs a warning messages with the given key/value pairs as context.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs a warning messages with the given message format with format specifier and arguments.

func WithName

func WithName(name string) logr.Logger

WithName adds a new element to the logger's name.

func WithValues

func WithValues(kvList ...interface{}) logr.Logger

WithValues adds some key-value pairs of context to a logger.

Types

type LoggerImpl

type LoggerImpl interface {
	logr.Logger

	// Infof logs a non-error messages with the given message format with format specifier and arguments.
	Infof(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{})
	// 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)

	CloneWithLevel(level int) LoggerImpl
}

LoggerImpl represents the ability to log messages, both errors and not.

func NewLogger

func NewLogger() LoggerImpl

NewLogger returns a new instance of the clusterctl.

func V

func V(level int) LoggerImpl

V returns an InfoLogger value for a specific verbosity level.

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)

	// SetChannel sets the channel to writer
	// if channel is set, writer will forward log messages to this log channel
	SetChannel(channel chan<- []byte)

	// QuietMode sets the logging mode to quiet
	// If this mode is set, writer will not write anything to stderr
	QuietMode(quiet bool)

	// SetVerbosity sets verbosity level and also updates default verbosity level
	SetVerbosity(verbosity int32)

	// SendProgressUpdate sends the progress to the listening logChannel
	SendProgressUpdate(status string, step string, totalSteps []string)
}

Writer defines methods to write and configure tkg writer

func NewWriter

func NewWriter() Writer

NewWriter returns new custom writter for tkg-cli

Jump to

Keyboard shortcuts

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