console

package
v0.0.0-...-c8a214a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

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

func Debug() *log.Logger

Debug returns a Logger to Stderr prefixed with "[debug]" if the log level is debug, otherwise it returns a no-op Logger.

func Error

func Error() *log.Logger

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

func Info() *log.Logger

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 Init

func Init(fs tbnflag.FlagSet)

Init binds the log level to a flag in the given FlagSet.

func ToWriteCloser

func ToWriteCloser(l *log.Logger) io.WriteCloser

ToWriteCloser wraps a *log.Logger and provides an implementation of io.WriteCloser

Types

type LogMessage

type LogMessage struct {
	Level   string
	Message string
}

LogMessage represents a console log level and message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL