msg

package
v0.0.0-...-32ca73d Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Blue   = "0;34"
	Red    = "0;31"
	Green  = "0;32"
	Yellow = "0;33"
	Cyan   = "0;36"
	Pink   = "1;35"
)

These contanstants map to color codes for shell scripts making them human readable.

Variables

View Source
var Default = NewMessanger()

Default contains a default messanger used by package level functions

Functions

func Color

func Color(code, msg string) string

Color returns a string in a certain color if colors are enabled and available on that platform.

func Debug

func Debug(msg string, args ...interface{})

Debug logs debug information using the Default Messanger

func Die

func Die(msg string, args ...interface{})

Die prints an error message and immediately exits the application using the Default Messanger. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.

func Error

func Error(msg string, args ...interface{})

Error logs and error using the Default Messanger

func ExitCode

func ExitCode(e int) int

ExitCode sets the exit code used by Die using the Default Messanger.

The default is 1.

Returns the old error code.

func HasErrored

func HasErrored() bool

HasErrored returns if Error has been called on the Default Messanger.

This is useful if you want to known if Error was called to exit with a non-zero exit code.

func Info

func Info(msg string, args ...interface{})

Info logs information using the Default Messanger

func Msg

func Msg(msg string, args ...interface{})

Msg prints a message with optional arguments, that can be printed, of varying types using the Default Messanger.

func Print

func Print(msg string)

Print prints exactly the string given using the Default Messanger.

It prints to Stdout.

func Puts

func Puts(msg string, args ...interface{})

Puts formats a message and then prints to Stdout using the Default Messanger.

It does not prefix the message, does not color it, or otherwise decorate it.

It does add a line feed.

func Warn

func Warn(msg string, args ...interface{})

Warn logs a warning using the Default Messanger

Types

type Messanger

type Messanger struct {
	sync.Mutex

	// Quiet, if true, suppresses chatty levels, like Info.
	Quiet bool

	// IsDebugging, if true, shows verbose levels, like Debug.
	IsDebugging bool

	// NoColor, if true, will not use color in the output.
	NoColor bool

	// Stdout is the location where this prints output.
	Stdout io.Writer

	// Stderr is the location where this prints logs.
	Stderr io.Writer

	// PanicOnDie if true Die() will panic instead of exiting.
	PanicOnDie bool
	// contains filtered or unexported fields
}

Messanger provides the underlying implementation that displays output to users.

func NewMessanger

func NewMessanger() *Messanger

NewMessanger creates a default Messanger to display output.

func (*Messanger) Color

func (m *Messanger) Color(code, msg string) string

Color returns a string in a certain color. The first argument is a string containing the color code or a constant from the table above mapped to a code.

The following will print the string "Foo" in yellow:

fmt.Print(Color(Yellow, "Foo"))

func (*Messanger) Debug

func (m *Messanger) Debug(msg string, args ...interface{})

Debug logs debug information

func (*Messanger) Die

func (m *Messanger) Die(msg string, args ...interface{})

Die prints an error message and immediately exits the application. If PanicOnDie is set to true a panic will occur instead of os.Exit being called.

func (*Messanger) Error

func (m *Messanger) Error(msg string, args ...interface{})

Error logs and error.

func (*Messanger) ExitCode

func (m *Messanger) ExitCode(e int) int

ExitCode sets the exit code used by Die.

The default is 1.

Returns the old error code.

func (*Messanger) HasErrored

func (m *Messanger) HasErrored() bool

HasErrored returns if Error has been called.

This is useful if you want to known if Error was called to exit with a non-zero exit code.

func (*Messanger) Info

func (m *Messanger) Info(msg string, args ...interface{})

Info logs information

func (*Messanger) Msg

func (m *Messanger) Msg(msg string, args ...interface{})

Msg prints a message with optional arguments, that can be printed, of varying types.

func (*Messanger) Print

func (m *Messanger) Print(msg string)

Print prints exactly the string given.

It prints to Stdout.

func (*Messanger) Puts

func (m *Messanger) Puts(msg string, args ...interface{})

Puts formats a message and then prints to Stdout.

It does not prefix the message, does not color it, or otherwise decorate it.

It does add a line feed.

func (*Messanger) Warn

func (m *Messanger) Warn(msg string, args ...interface{})

Warn logs a warning

Jump to

Keyboard shortcuts

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