Documentation
¶
Index ¶
Constants ¶
const TermWidthEnv = "TERM_WIDTH"
TermWidthEnv is the name of the environment variable that can be used to override the TermWidth value.
Variables ¶
var TermWidth = lo.CoalesceOrEmpty(getTermWidth(), 80)
TermWidth is the default rendering width used for terminal output.
It may be overridden by setting the TermWidthEnv environment variable.
Functions ¶
func RenderWithChildJSON ¶
RenderWithChildJSON automatically renders a parent with its child in JSON format.
func RenderWithChildTerminal ¶
RenderWithChildTerminal automatically renders a parent with its child in terminal format.
Types ¶
type AnimatedMessage ¶
type AnimatedMessage interface {
// RunTerminal starts rendering the message in dynamic mode. The returned channel is subscribed by the logger to
// render the message in real-time.
//
// The CI flag is passed for environments where real-time outputs might result in loads of repetitive logs
// (building docker image for example). In this case, only relevant updates should be sent to the chan.
RunTerminal(ci bool) <-chan string
// RunJSON is similar to RunTerminal but tailored for JSON output. The CI flag is assumed to always be true.
RunJSON() <-chan map[string]interface{}
// Close terminates the logger, and releases all its resources.
Close()
}
AnimatedMessage allow a Message to produce an output that is dynamically updated.
type Level ¶
type Level string
Level specify the importance of the log message. Some implementations may use different channels depending on the log level.
const ( // LevelInfo is the lowest log level. It is used for general information messages. LevelInfo Level = "INFO" // LevelWarning is used for messages that are not errors but may require attention. LevelWarning Level = "WARNING" // LevelError is used for messages that indicate an error occurred. LevelError Level = "ERROR" // LevelFatal is used for messages that indicate a fatal error occurred. A logger implementation should // automatically exit the program, or trigger a crash, after logging a message with this level. LevelFatal Level = "FATAL" )
type Logger ¶
type Logger interface {
// Log a message with the specified level.
Log(level Level, message Message)
// LogAnimated logs a message that can be updated in real-time.
//
// Running an animated log prevents new messages from being printed until the animated log is closed.
// Attempting to log while an animated message is running will cause a panic.
LogAnimated(message AnimatedMessage) (cleaner func())
}
type Message ¶
type Message interface {
// RenderTerminal renders a message in a format that is suitable for terminal output.
RenderTerminal() string
// RenderJSON renders a message in a format that is suitable for JSON output.
RenderJSON() map[string]interface{}
}
Message is a generic representation of a data that supports rendering under different formats.