Documentation
¶
Overview ¶
package log provides logging mechanisms This file defines animator options to be used with AnimateProgressWithOptions
Package log provides logging mechanisms. It offers logging functionality that can include stylized logs, updating progress dots (...), and emojis. It respects a TTY parameter. When set to false, all stylization is removed.
Index ¶
- Variables
- type AnimatorOption
- type CMDLogger
- 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 colors.Attribute) Logger
- func (l *CMDLogger) V(level int) Logger
- func (l *CMDLogger) Warn(message string)
- func (l *CMDLogger) Warnf(message string, args ...interface{})
- type Logger
- type LoggerOptions
- func WithColor(color colors.Attribute) LoggerOptions
- func WithLeftPadIndent(indent int) LoggerOptions
- func WithLogFile(filePath string) LoggerOptions
- func WithLogLevel(logLevel int) LoggerOptions
- func WithLogVerbosity(verbosity int) LoggerOptions
- func WithOutputWriter(writer io.Writer) LoggerOptions
- func WithTermFileDescriptor(termFd int) LoggerOptions
- func WithTty(isTty bool) LoggerOptions
Constants ¶
This section is empty.
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) 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 colors.Attribute) Logger }
Logger provides the logging interaction for the application.
func NewLogger ¶
func NewLogger(options ...LoggerOptions) (Logger, error)
NewLogger returns an instance of Logger, implemented via CMDLogger.
type LoggerOptions ¶
type LoggerOptions interface {
// contains filtered or unexported methods
}
LoggerOptions an option to be passed to the NewLogger constructor
func WithColor ¶ added in v0.2.0
func WithColor(color colors.Attribute) LoggerOptions
func WithLeftPadIndent ¶ added in v0.2.0
func WithLeftPadIndent(indent int) LoggerOptions
func WithLogFile ¶ added in v0.2.0
func WithLogFile(filePath string) LoggerOptions
func WithLogLevel ¶ added in v0.2.0
func WithLogLevel(logLevel int) LoggerOptions
func WithLogVerbosity ¶ added in v0.2.0
func WithLogVerbosity(verbosity int) LoggerOptions
func WithOutputWriter ¶ added in v0.2.0
func WithOutputWriter(writer io.Writer) LoggerOptions
func WithTermFileDescriptor ¶ added in v0.2.0
func WithTermFileDescriptor(termFd int) LoggerOptions
func WithTty ¶ added in v0.2.0
func WithTty(isTty bool) LoggerOptions