README.md
1
2[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/cortesi/termlog)
3[![Travis Build Status](https://travis-ci.org/cortesi/termlog.svg?branch=master)](https://travis-ci.org/cortesi/termlog)
4[![Build status](https://ci.appveyor.com/api/projects/status/gxuitoksv66sky3l/branch/master?svg=true)](https://ci.appveyor.com/project/cortesi/termlog/branch/master)
5
6
7
8# termlog: Logging for interactive terminals
9
10![screenshot](_demo/screenshot.png "termlog in action")
11
12# Basic usage
13
14 l := termlog.NewLog()
15 l.Say("Log")
16 l.Notice("Notice!")
17 l.Warn("Warn!")
18 l.Shout("Error!")
19
20Each log entry gets a timestamp.
21
22
23# Groups
24
25Groups collect entries together under a single timestamp, with subsequent lines
26indented:
27
28 g = l.Group()
29 g.Say("This line gets a timestamp")
30 g.Say("This line will be indented with no timestamp")
31 g.Done()
32
33Groups produce no output until the .Done() method is called - a good use for
34defer. Termlog ensures that all grouped entries appear together in output.
35
36
37# Streams
38
39Streams associate log entries with a header. New stream log entries only get a
40header if another log source (i.e. a different stream, group, or plain log) has
41produced output in the meantime. Each stream log entry gets its own timestamp.
42
43 g = l.Stream("This is the header")
44 g.Say("The header will be printed before this line")
45 g.Say("But not before this one")
46 g.Done()
47
48
49# Named logs
50
51Log entries can be named using the *As methods:
52
53 l := termlog.NewLog()
54 l.Say("hello")
55 l.SayAs("debug", "Some debugging info")
56
57Named entries are always silenced, unless they've been enabled specifically, like so:
58
59 l.Enable("debug")
60
61
62# Specified colors
63
64The package is compatible with the color specifications from
65github.com/fatih/color, which means that colors can be composed like this:
66
67 l.Say("Here are some composed colors...")
68 l.Say(
69 "%s %s %s",
70 color.RedString("red"),
71 color.GreenString("green"),
72 color.BlueString("blue"),
73 )
74