console

package module
v0.0.0-...-45a3ca7 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: MIT Imports: 4 Imported by: 11

README

cameo/console

A simple configurable output console

Allows initialization with verbose and/or debug options.

Use throughout your program code to output simple information to the console.

Intro

While developing and debuging it is often useful to output debug information to the console that would not normally be visible to the user. It is also often desired to include a verbose mode of operation for command line utilities. This utility library provides a simple way to acomplish this as well as output to Standard Out and Standard Error.

Messages types
  • Always messages are always output to Standard Out
  • Error messages are always sent to Standard Error
  • Debug messages are only output to Standard Out if IsDebug() == true
  • Verbose messages are only output to Standard Out if IsVerbose() == true or IsDebug() == true
Redirect StdOut and StdErr

By default messages are sent to os.Stdout and os.Stderr. If you desire to send messages to another location use RedirectIO(io.writer, io.writer)

To connect to a logging system simply provide an io.writer that outputs to your logger.

Docs

GoDoc

Usage Examples

Instance
...
import "github.com/caimeo/console"
...
con := console.New(true, true)

con.Always("Message to User")
con.Debug("Some debugging info")
con.Error("OMG an error!")
...
Static/Singleton
import "github.com/caimeo/console"
...
console.Init(true, true)
...
console.Debug("Some info Debug data", v1, v2)
console.Always("Message to User")
...

import "github.com/caimeo/console"
...
console.Debug("A message in another file"")
...

Mixed

It is also possible to mix these methods.

...
import "github.com/caimeo/console"
...
con := console.Init(true, true)

con.Always("Message to User via an instance")
console.Always("Message to user via singleton")

or

...
import "github.com/caimeo/console"
...
console.Init(true, true)
console.Always("Message to user via singleton")

con := console.Instance()
con.Always("Message to User via an instance")

Pull requests are welcome.

Caimeo Prime
Caimeo Operating Group

Documentation

Overview

cameo/console

A simple configurable output console

Allows initialization with verbose and/or debug options.

Use throughout your program code to output simple information to the console.

Intro

While developing and debuging it is often useful to output debug information to the console that would not normally be visible to the user. It is also often desired to include a verbose mode of operation for command line utilities. This utility library provides a simple way to acomplish this as well as output to Standard Out and Standard Error.

Messages types:

- Always: messages are always output to Standard Out

- Error: messages are always sent to Standard Error

- Debug: messages are only output to Standard Out if IsDebug() == true

- Verbose: messages are only output to Standard Out if IsVerbose() == true or IsDebug() == true

Redirect StdOut and StdErr

By default messages are sent to os.Stdout and os.Stderr. If you desire to send messages to another location use RedirectIO(io.writer, io.writer)

To connect to a logging system simply provide an io.writer that outputs to your logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Always

func Always(args ...interface{})

always writes to stdout

func Debug

func Debug(args ...interface{})

writes to stdout if IsDebug == ture

func Error

func Error(args ...interface{})

always writes to stderr

func IsDebug

func IsDebug() bool

returns true if debug mode is turned on

func IsVerbose

func IsVerbose() bool

returns true if verbose mode is turned on

func RedirectIO

func RedirectIO(stdIoWriter io.Writer, errIoWriter io.Writer)

Allows redirection of std and err to arbitrary io writers

func StdErr

func StdErr(args ...interface{})

Outputs to standard error as a single line

func StdOut

func StdOut(args ...interface{})

Outputs to standard out as a single line

func Verbose

func Verbose(args ...interface{})

writes to stdout if IsVerbose == true or IsDebug == true

Types

type Console

type Console interface {
	Always(args ...interface{})
	Verbose(args ...interface{})
	Debug(args ...interface{})
	Error(args ...interface{})
	IsVerbose() bool
	IsDebug() bool
}

func Init

func Init(verbose bool, debug bool) Console

func Instance

func Instance() Console

func New

func New(verbose bool, debug bool) Console

Jump to

Keyboard shortcuts

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