cmdlog

package module
v0.0.0-...-be49349 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: ISC Imports: 10 Imported by: 3

README

cmdlog

example output

cmdlog implements colored leveled logging for command line tools.

cmdlog supports arbitrary randomly colored prefixes just like terrastruct/ci.

l := cmdlog.New(xos.NewEnv(os.Environ()), os.Stderr)
l = l.WithCCPrefix("lochness")
l = l.WithCCPrefix("imgbundler")
l = l.WithCCPrefix("cache")

l.NoLevel.Println("Somehow, the world always affects you more than you affect it.")

l.SetDebug(true)
l.Debug.Println("Man is a rational animal who always loses his temper when he is called upon.")

l.SetDebug(false)
l.Debug.Println("You can never trust a woman; she may be true to you.")

l.SetTS(true)
l.Success.Println("An alcoholic is someone you don't like who drinks as much as you do.")
l.Info.Println("There once was this swami who lived above a delicatessan.")

l.SetTSFormat(time.UnixDate)
l.Warn.Println("Telephone books are like dictionaries -- if you know the answer before.")

l.SetTS(false)
l.Error.Println("Nothing can be done in one trip.")

Output is the screenshot above. You can run the example yourself. It's in ./example/main.go.

See ./cmdlog_test.go for further usage.

You can log in tests with NewTB.

You may also find the ./xterm package useful for outputting formatted text to the terminal.

  • $COLOR is obeyed to force enable/disable colored output.
  • $DEBUG is obeyed to enable/disable debug logs.

Install

go get oss.terrastruct.com/cmdlog@latest

Documentation

Overview

Package cmdlog implements color leveled logging for command line tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	NoLevel *log.Logger
	Debug   *log.Logger
	Success *log.Logger
	Info    *log.Logger
	Warn    *log.Logger
	Error   *log.Logger
	// contains filtered or unexported fields
}

func New

func New(env *xos.Env, w io.Writer) *Logger

func NewTB

func NewTB(env *xos.Env, tb testing.TB) *Logger

func (*Logger) GetDebug

func (l *Logger) GetDebug() bool

func (*Logger) GetTS

func (l *Logger) GetTS() bool

func (*Logger) GetTSFormat

func (l *Logger) GetTSFormat() string

func (*Logger) SetDebug

func (l *Logger) SetDebug(enabled bool)

func (*Logger) SetTS

func (l *Logger) SetTS(enabled bool)

func (*Logger) SetTSFormat

func (l *Logger) SetTSFormat(tsfmt string)

func (*Logger) WithCCPrefix

func (l *Logger) WithCCPrefix(s string) *Logger

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(caps, s string) *Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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