Documentation ¶
Overview ¶
Package log provides functionality to output human readable, colorful test to STDOUT and STDERR. It's best used for programs, such as CLI apps, that write output to people rather than machines. It is not intended for logging to log aggregators or other systems. It takes advantage of the github.com/deis/pkg/prettyprint to provide colorful output.
This package provides global functions for use as well as a 'Logger' struct that you can instantiate at-will for customized logging. All global funcs operate on a DefaultLogger, which is pre-configured to log to os.Stdout and os.Stderr, with debug logs turned off.
Example usage of global functions:
import "github.com/deis/pkg/log" log.Info("Hello Gophers!") // equivalent of log.DefaultLogger.Info("hello gophers!") log.Debug("log.DefaultLogger initializes with debug logs turned off, so you can't see me!") log.DefaultLogger.SetDebug(true) log.Debug("Now that we turned debug logs on, you can see me now!")
Example usage of instantiating an individual logger:
// create a new logger that sends all stderr logs to /dev/null, and turns on debug logs logger := log.NewLogger(os.Stdout, iouitl.Discard, true) log.Debug("Hello Gophers!")
Package log is a convenience wrapper for logging messages of various levels (associated colors to come) to the terminal. Much of this code has been shamelessly stolen from https://github.com/helm/helm/blob/master/log/log.go
Index ¶
- Constants
- Variables
- func CleanExit(format string, v ...interface{})
- func Debug(msg string, v ...interface{})
- func Die(format string, v ...interface{})
- func Err(format string, v ...interface{})
- func Info(format string, v ...interface{})
- func Msg(format string, v ...interface{})
- func Warn(format string, v ...interface{})
- type Color
- type Logger
- func (l *Logger) CleanExit(format string, v ...interface{})
- func (l *Logger) Debug(msg string, v ...interface{})
- func (l *Logger) Die(format string, v ...interface{})
- func (l *Logger) Err(format string, v ...interface{})
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Msg(format string, v ...interface{})
- func (l *Logger) SetDebug(debug bool)
- func (l *Logger) SetStderr(w io.Writer)
- func (l *Logger) SetStdout(w io.Writer)
- func (l *Logger) Warn(format string, v ...interface{})
Constants ¶
const ( DebugPrefix = "[DEBUG]" ErrorPrefix = "[ERROR]" WarnPrefix = "[WARN]" InfoPrefix = "--->" )
Variables ¶
var ( // Default resets the console color Default = Color(prettyprint.Colors["Default"]) // Red sets the console color to red Red = Color(prettyprint.Colors["Red"]) // Cyan sets the console color to cyan Cyan = Color(prettyprint.Colors["Cyan"]) // Yellow sets the console color to yellow Yellow = Color(prettyprint.Colors["Yellow"]) // Green sets the console color to green Green = Color(prettyprint.Colors["Green"]) )
DefaultLogger is the default logging implementation. It's used in all top level funcs inside the log package, and represents the equivalent of NewLogger(os.Stdout, os.Stderr)
Functions ¶
func CleanExit ¶
func CleanExit(format string, v ...interface{})
CleanExit is a convenience function for DefaultLogger.CleanExit(...)
func Debug ¶
func Debug(msg string, v ...interface{})
Debug is a convenience function for DefaultLogger.Debug(...)
func Die ¶
func Die(format string, v ...interface{})
Die is a convenience function for DefaultLogger.Die(...)
func Err ¶
func Err(format string, v ...interface{})
Err is a convenience function for DefaultLogger.Err(...)
func Info ¶
func Info(format string, v ...interface{})
Info is a convenience function for DefaultLogger.Info(...)
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the base logging struct from which all logging functionality stems
func NewLogger ¶
NewLogger creates a new logger bound to a stdout and stderr writer, which are most commonly os.Stdout and os.Stderr, respectively
func (*Logger) Msg ¶
Msg passes through the formatter, but otherwise prints exactly as-is.
No prettification.
func (*Logger) SetDebug ¶
SetDebug sets the internal debugging field on or off. This func is not concurrency safe.
func (*Logger) SetStderr ¶ added in v0.5.0
SetStderr sets the internal stderr writer. This func is not concurrency safe.