Documentation
¶
Overview ¶
package log provides logging mechanisms This file defines animator options to be used with AnimateProgressWithOptions
Package log provides logging mechanisms for the tanzu unmanaged-cluster CLI plugin. It offers logging functionality that can include stylized logs, updating progress dots (...), and emojis. It also respects a TTY parameter. When set to false, all stylization is removed.
Index ¶
- Constants
- Variables
- type AnimatorOption
- type CMDLogger
- func (l *CMDLogger) AddLogFile(filePath string)
- func (l *CMDLogger) AnimateProgressWithOptions(options ...AnimatorOption)
- func (l *CMDLogger) Error(message string)
- func (l *CMDLogger) Errorf(message string, args ...interface{})
- func (l *CMDLogger) Event(emoji, message string)
- func (l *CMDLogger) Eventf(emoji, message string, args ...interface{})
- func (l *CMDLogger) Info(message string)
- func (l *CMDLogger) Infof(message string, args ...interface{})
- func (l *CMDLogger) ReplaceLinef(message string, args ...interface{})
- func (l *CMDLogger) Style(indent int, c color.Attribute) Logger
- func (l *CMDLogger) V(level int) Logger
- func (l *CMDLogger) Warn(message string)
- func (l *CMDLogger) Warnf(message string, args ...interface{})
- func (l *CMDLogger) Writer(writer io.Writer)
- type Logger
Constants ¶
const ( // The following are a set of emoji codes that can be used // with the Event and Eventf logging methods in this package. // They should all take up 2 terminal columns. // https://www.unicode.org/emoji/charts/full-emoji-list.html WrenchEmoji = "\U0001F527" FolderEmoji = "\U0001F4C1" PictureEmoji = "\U0001F3A8" PackageEmoji = "\U0001F4E6" RocketEmoji = "\U0001F680" EnvelopeEmoji = "\U0001F4E7" GlobeEmoji = "\U0001F310" GreenCheckEmoji = "\U00002705" ControllerEmoji = "\U0001F3AE" TestTubeEmoji = "\U0001F9EA" MagnetEmoji = "\U0001F9F2" )
Variables ¶
var DefaultLogLevel = 0
DefaultLogLevel controls the default verbosity of log messages.
Functions ¶
This section is empty.
Types ¶
type AnimatorOption ¶
type AnimatorOption interface {
// contains filtered or unexported methods
}
AnimatorOption is an option to be passed to the AnimateProgressWithOptions logging method
func AnimatorWithContext ¶
func AnimatorWithContext(ctx context.Context) AnimatorOption
AnimatorWithContext provides a context to the async call. That context can be canceled which stops the animation. Ex: AnimatorWithContext(myContext)
func AnimatorWithMaxLen ¶
func AnimatorWithMaxLen(l int) AnimatorOption
AnimatorWithMaxLen sets the maximum number of dots to animate Ex:AnimatorWithMaxLen(3)
func AnimatorWithMessagef ¶
func AnimatorWithMessagef(formatString string, formatArgs ...string) AnimatorOption
AnimatorWithMessagef sets the format string message and any format arguments to use Ex: AnimatorWithMessagef("Downloading to: %s", filePathLocation)
If no format arguments are provided, just the message will be displayed when animating Ex: AnimatorWithMessagef("Creating controller")
If a status channel is used, the first format argument in the template string _must_ be the status associated with the status channel Ex: AnimatorWithMessagef("controller status: %s")
func AnimatorWithStatusChan ¶
func AnimatorWithStatusChan(s chan string) AnimatorOption
AnimatorWithStatusChan sets a string status channel that will be used to asynchronously inspect the status of an operation Ex: AnimatorWithStatusChan(myStatusChan)
type CMDLogger ¶
type CMDLogger struct {
// contains filtered or unexported fields
}
CMDLogger is the logger implementation used for high-level command line logging.
func (*CMDLogger) AddLogFile ¶
func (*CMDLogger) AnimateProgressWithOptions ¶
func (l *CMDLogger) AnimateProgressWithOptions(options ...AnimatorOption)
func (*CMDLogger) ReplaceLinef ¶
type Logger ¶
type Logger interface { // Event takes an emoji codepoint (e.g. "\U0001F609") and presents a log message on it's own line. // This package provides several standard emoji codepoints as string constants. I.e: logger.HammerEmoji // Warning: Emojis may have variable width and this method assumes 2 width emojis, adding a space between the emoji and message. // Emojis provided in this package as string consts have 2 width and work with this method. // If you wish for additional space, add it at the beginning of the message (string) argument. Event(emoji, message string) // Eventf takes an emoji codepoint (e.g. "\U0001F609"), a format string, arguments for the format string. // This package provides several standard emoji codepoints as string constants. I.e: logger.HammerEmoji // Warning: Emojis may have variable width and this method assumes 2 width emojis, adding a space between the emoji and message. // Emojis provided in this package as string consts have 2 width and work with this method. // If you wish for additional space, add it at the beginning of the message (string) argument. Eventf(emoji, message string, args ...interface{}) // Info prints a standard log message. // Line breaks are automatically added to the end. Info(message string) // Infof takes a format string, arguments, and prints it as a standard log message. // Line breaks are not automatically added to the end. Infof(message string, args ...interface{}) // Warn prints a warning message. When TTY is enabled (default), it will be stylized as yellow. // Line breaks are automatically added to the end. Warn(message string) // Warnf takes a format string, arguments, and prints it as a warning message. // When TTY is enabled (default), it will be stylized as yellow. // Line breaks are not automatically added to the end. Warnf(message string, args ...interface{}) // Error prints an error message. When TTY is enabled (default), it will be stylized as red. // Line breaks are automatically added to the end. Error(message string) // Errorf takes a format string, arguments, and prints it as an error message. // When TTY is enabled (default), it will be stylized as yellow. // Line breaks are not automatically added to the end. Errorf(message string, args ...interface{}) // ReplaceLinef takes a template string message // and any optional format arguments // and replaces the current line. // This is useful after canceling AnimateProgressWithOptions and needing to print a final "success" message // Ex: ReplaceLinef("Finished reconciling controller: %s", controllerStatus) ReplaceLinef(message string, args ...interface{}) // AnimateProgressWithOptions takes any number of AnimatorOptions // and is used to async animate a number of dots. // See the AnimatorOptions for further documentation // Ex: AnimateProgressWithOptions(AnimatorWithMaxLen(5)) AnimateProgressWithOptions(options ...AnimatorOption) // V sets the level of the log message based on an integer. The logger implementation will hold a configured // log level, which this V level is assessed against to determine whether the log message should be output. V(level int) Logger // Style provides indentation and colorization of log messages. The indent argument specifies the amount of " " // characters to prepend to the message. The color should be specified using color constants in this package. Style(indent int, c color.Attribute) Logger // AddLogFile adds a file name to log all activity to. AddLogFile(filePath string) // Writer provides a way to customize the io.Writer object used to dump the logs. This defaults to os.Stdout Writer(writer io.Writer) }
Logger provides the logging interaction for the application.