package
0.0.0-20210329234232-2eeca3e37d20
Repository: https://github.com/intel-hpdd/logging.git
Documentation: pkg.go.dev
# README
applog -- The Application Logger
The applog library takes a UI-focused approach to logging for an application. It's primarily intended to be used for informing the application user of things like in-progress tasks, errors, and important messages.
The library is also intended to make supporting an application easier, by logging everything, even if it only displays a subset of information to the user.
Examples
package main
import (
"time"
"github.com/whamcloud/logging/applog"
)
func main() {
applog.StartTask("Doing some long-running process")
time.Sleep(10 * time.Second)
applog.EndTask()
name := "Fred"
if 2 + 2 == 5 {
applog.Fail("Reality is broken, %s!", name)
} else {
applog.User("Things are fine, %s!", name)
}
}
Will display something like (with a spinner until complete):
Doing some long-running process... Done.
Things are fine, Fred!
All but the final EndTask() call may be omitted if there is a sequential series of tasks started with StartTask().
A call to Fail() with an error object will prepend the text "ERROR: " to the Error() string before exiting, otherwise it just prints the arguments before exiting.
# Functions
CompleteTask stops the spinner and prints a newline.
Debug logs the entry and prints to stdout if level <= DEBUG.
DisplayLevel sets the logger's display level.
Fail logs the entry and prints to stderr if level <= FAIL.
IsTerminal returns true if the given file descriptor is a terminal.
JournalFile configures the logger's journaler.
New returns a new AppLogger.
SetJournal sets the standard logger's journal writer.
SetLevel sets the standard logger's display level.
SetStandard sets the standard logger to the supplied logger.
StandardLogger returns the standard logger configured by the library.
StartTask logs the entry at USER level and displays a spinner for long-running tasks.
Trace logs the entry and prints to stdout if level <= TRACE.
User logs the entry and prints to stdout if level <= USER.
Warn logs the entry and prints to stderr if level <= WARN.
Writer returns an io.Writer for injecting our logging into 3rd-party libraries.
WriterIsTerminal returns true if the given io.Writer converts to an *os.File and the file's fd is a terminal.
# Structs
AppLogger is a logger with methods for displaying entries to the user after recording them to a journal.
LoggedWriter implements io.Writer and is used to redirect logging from 3rd-party libraries to this library.
# Type aliases
OptSetter sets logger options.