Documentation
¶
Overview ¶
Package termlog provides facilities for logging to a terminal geared towards interactive use. Basic usage looks like this:
l := termlog.NewLog() l.Say("Log") l.Notice("Notice!") l.Warn("Warn!") l.Shout("Error!") Each log entry gets a timestamp. Entries can be grouped together under one timestamp, with subsequent lines indented like so: g = l.Group() g.Say("This line gets a timestamp") g.Say("This line will be indented with no timestamp") g.Done()
Groups must be marked as .Done() before output is produced - a good use for defer.
The package is compatible with the color specifications from github.com/fatih/color, which means that colors can be composed like this:
g = l.Group() g.Say("Here are some composed colours...") g.Say( "%s %s %s", color.RedString("red"), color.GreenString("green"), color.BlueString("blue"), )
The *As logging functions tag a line with an identity. All tagged lines are silenced unless explicitly enabled on the Logger with the .Enable() method.
Index ¶
- Variables
- func NewContext(ctx context.Context, logger Logger) context.Context
- type Group
- func (g *Group) Done()
- func (g *Group) Group() Logger
- func (g *Group) Notice(format string, args ...interface{})
- func (g *Group) NoticeAs(name string, format string, args ...interface{})
- func (g *Group) Quiet()
- func (g *Group) Say(format string, args ...interface{})
- func (g *Group) SayAs(name string, format string, args ...interface{})
- func (g *Group) Shout(format string, args ...interface{})
- func (g *Group) ShoutAs(name string, format string, args ...interface{})
- func (g *Group) Warn(format string, args ...interface{})
- func (g *Group) WarnAs(name string, format string, args ...interface{})
- type Log
- func (l *Log) Done()
- func (l *Log) Enable(name string)
- func (l *Log) Group() Logger
- func (*Log) NoColor()
- func (l *Log) Notice(format string, args ...interface{})
- func (l *Log) NoticeAs(name string, format string, args ...interface{})
- func (l *Log) Quiet()
- func (l *Log) Say(format string, args ...interface{})
- func (l *Log) SayAs(name string, format string, args ...interface{})
- func (l *Log) Shout(format string, args ...interface{})
- func (l *Log) ShoutAs(name string, format string, args ...interface{})
- func (l *Log) Warn(format string, args ...interface{})
- func (l *Log) WarnAs(name string, format string, args ...interface{})
- type Logger
- type Palette
Constants ¶
This section is empty.
Variables ¶
var DefaultPalette = Palette{ Say: color.New(), Notice: color.New(color.FgBlue), Warn: color.New(color.FgYellow), Shout: color.New(color.FgRed), Timestamp: color.New(color.FgCyan), }
DefaultPalette is a sensbile default palette, with the following foreground colours:
Say: Terminal default Notice: Blue Warn: Yellow Shout: Red Timestamp: Cyan
Functions ¶
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a group of lines that constitue a single log entry that won't be split. Lines in a group are indented.
type Log ¶
type Log struct { Palette *Palette // contains filtered or unexported fields }
Log has a level cutoff
type Logger ¶
type Logger interface { Say(format string, args ...interface{}) Notice(format string, args ...interface{}) Warn(format string, args ...interface{}) Shout(format string, args ...interface{}) SayAs(name string, format string, args ...interface{}) NoticeAs(name string, format string, args ...interface{}) WarnAs(name string, format string, args ...interface{}) ShoutAs(name string, format string, args ...interface{}) Done() Quiet() Group() Logger }
Logger logs things
func FromContext ¶
FromContext retrieves a logger from a context