Documentation ¶
Index ¶
- Variables
- type CliLogBox
- type CliLogBoxTask
- type LogBuffer
- func (buf *LogBuffer) Fire(entry *log.Entry) error
- func (buf *LogBuffer) InterceptLoggers()
- func (buf *LogBuffer) Levels() []log.Level
- func (buf *LogBuffer) PrintMessages(w io.Writer, max_num int) (err error)
- func (buf *LogBuffer) PushMessage(msg string)
- func (buf *LogBuffer) RegisterMessageHooks()
- func (buf *LogBuffer) RestoreLoggers()
- type TerminalWindowSize
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTerminalWindowSize is used as a default result by GetTerminalSize() if the real // terminal size cannot be determined. DefaultTerminalWindowSize = TerminalWindowSize{ Row: 50, Col: 160, Xpixel: 0, Ypixel: 0, } )
Functions ¶
This section is empty.
Types ¶
type CliLogBox ¶
type CliLogBox struct { // LogBuffer provides the underlying functionality for capturing log messages. // CliLogBox acts like an extension of LogBuffer. After calling Init(), // the log capturing must be taken care of using RegisterMessageHooks(), // InterceptLogger() and RestoreLogger(). *LogBuffer // NoUtf8 can be set to true to replace UTF8 border drawing characters with // regular ASCII characters. NoUtf8 bool // LogLines configures the minimum number of log entries that must remain visible // in the lower part of the console box. The log entries are appended directly // to the actual output and usually take the rest of the screen. If the box content // is so long, that it would leave less than LogLines log entries, the content is // truncated. The truncation is visualized by three dots in the separator line // between the content and the log entries. LogLines int // MessageBuffer configures the number of messages stored in the underlying LogBuffer. MessageBuffer int }
CliLogBox can display a box spanning over the entire command-line screen containing arbitrary content that can be updated from outside, and an additional section at the bottom containing log messages captured using a LogBuffer.
func (*CliLogBox) Init ¶
func (box *CliLogBox) Init()
Init initializes the underlying LogBuffer and should be called before any other methods.
func (*CliLogBox) Update ¶
Updates refreshes the entire display output. It can be called in arbitrary time intervals, but should never be called concurrently. The content must be written by the given function, which also receives the width of the screen. If it prints lines that are longer than the screen width, they will be cut off. It can produce an arbitrary number of lines.
type CliLogBoxTask ¶
type CliLogBoxTask struct { CliLogBox // UpdateInterval configures the wait-period between screen-refresh cycles. UpdateInterval time.Duration // MinUpdateInterval can be set to >0 to reduce the screen-refresh frequency // even if TriggerUpdate() is called more frequently than every MinUpdateInterval. MinUpdateInterval time.Duration // Update is called on every refresh cycle to fill the screen with content. // See also CliLogBox.Update(). Update func(out io.Writer, width int) error // contains filtered or unexported fields }
CliLogBoxTask implements the golib.Task interface by creating a CliLogBox, capturing all log entries, and regularly updating the screen in a separate goroutine.
func (*CliLogBoxTask) Init ¶
func (t *CliLogBoxTask) Init()
Init initializes the receiver and starts collecting log messages. It should be called as early as possible in order to not miss any log messages. If any log message is fire before calling this, it will not be displayed in the log box, and the log box will overwrite the log message on the console.
func (*CliLogBoxTask) Start ¶
func (t *CliLogBoxTask) Start(wg *sync.WaitGroup) golib.StopChan
Start implements the golib.Task interface. It intercepts the default logger and starts a looping goroutine for refreshing the screen content. When the task is stopped, it will automatically restore the operation of the default logger.
func (*CliLogBoxTask) Stop ¶
func (t *CliLogBoxTask) Stop()
Stop stops the goroutine performing screen refresh cycles, and restores the operation of the default logger.
func (*CliLogBoxTask) String ¶
func (t *CliLogBoxTask) String() string
String implements the golib.Task interface.
func (*CliLogBoxTask) TriggerUpdate ¶
func (t *CliLogBoxTask) TriggerUpdate()
Update triggers an immediate screen update.
type LogBuffer ¶
type LogBuffer struct { // PushMessageHook is called each time a message is a added to this LogBuffer, // regardless if it was added from a logger or explicitly over PushMessage(). PushMessageHook func(newMessage string) // contains filtered or unexported fields }
LogBuffer can be used to intercept the default logger of the "github.com/sirupsen/logrus" package and store all messages to a ring-buffer instead of outputting them directly.
func NewDefaultLogBuffer ¶ added in v0.0.4
NewDefaultLogBuffer creates a new LogBuffer of the given buffer size, that captures the logs of the default logger of the"github.com/sirupsen/logrus" package, and of the golib package.
func NewLogBuffer ¶
NewLogBuffer allocates a new LogBuffer instance with the given size for the message ring buffer.
func (*LogBuffer) Fire ¶
Fire will be called with incoming log entries after RegisterMessageHooks() has been called. It uses the log formatter of the entry to format the message to a string and stores it using PushMessage().
func (*LogBuffer) InterceptLoggers ¶ added in v0.0.4
func (buf *LogBuffer) InterceptLoggers()
InterceptLogger makes the registered loggers stop logging to their real output. The original logging output is stored, so it can be restored later with RestoreLogger().
func (*LogBuffer) Levels ¶
Levels return all numbers in 0..255 to indicate that the LogBuffer will handle log messages of any level.
func (*LogBuffer) PrintMessages ¶
PrintMessages prints all stored messages to the given io.Writer instance, optionally limiting the number of printed messages through the max_num parameter.
func (*LogBuffer) PushMessage ¶
PushMessage adds a message to the message ring buffer.
func (*LogBuffer) RegisterMessageHooks ¶ added in v0.0.4
func (buf *LogBuffer) RegisterMessageHooks()
RegisterMessageHooks registers a hook for receiving log messages from all registered loggers. This should be called as early as possible in order to not miss any log messages. Any messages created prior to this will not be captured by the LogBuffer.
func (*LogBuffer) RestoreLoggers ¶ added in v0.0.4
func (buf *LogBuffer) RestoreLoggers()
RestoreLogger restored the original logger output of the default logger of the "github.com/sirupsen/logrus" package. InterceptLogger() must have been called prior to this.
type TerminalWindowSize ¶ added in v0.0.16
TerminalWindowSize contains known bounds in rows, columns and pixels of the console behind the standard output.
func GetTerminalSize ¶ added in v0.0.16
func GetTerminalSize() TerminalWindowSize
GetTerminalSize tries to retrieve information about the size of the console behind the standard output. If the query fails, it prints a warning to the logger and returns the default value DefaultTerminalWindowSize.