Documentation ¶
Overview ¶
Package console provides simple console logging to Stderr, configurable through a FlagSet. There are three levels of logging:
- none
- error
- debug
The default log level is error.
Executable using the console package should include exactly one call to Init() with the flag.FlagSet used to configure the executable, passed prior to the FlagSet being parsed. Subsequently, calls to Error() and Debug() will produce output to os.Stderr, based on the log-level configured.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumeConsoleLogs ¶
func ConsumeConsoleLogs(capacity int) (<-chan LogMessage, func())
ConsumeConsoleLogs allows log messages to be temporarily diverted to a channel for testing. Messages created via the Info, Error, or Debug loggers are sent to the returned channel, which is created with the given capacity. If the channel is full, subsequent calls to any of the loggers will block. The returned function must be called to restore the default output. Nested calls of ConsumeConsoleLogs are not supported.
This method is intended to aid in testing code that uses the console package and should not be used outside tests.
func Debug ¶
Debug returns a Logger to Stderr prefixed with "[debug]" if the log level is debug, otherwise it returns a no-op Logger.
func Error ¶
Error returns a Logger to Stderr prefixed with "[error]" if the log level is error, info, or debug, otherwise it returns a no-op Logger.
func Info ¶
Info returns a Logger to Stderr prefixed with "[info]" if the log level is info or error, otherwise it returns a no-op Logger.
func ToWriteCloser ¶
func ToWriteCloser(l *log.Logger) io.WriteCloser
ToWriteCloser wraps a *log.Logger and provides an implementation of io.WriteCloser
Types ¶
type LogMessage ¶
LogMessage represents a console log level and message.