forked from visionmedia/go-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
51 lines (41 loc) · 1.19 KB
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"time"
. "github.com/nmccready/go-debug"
. "github.com/nmccready/go-debug/example/readme/pkg"
)
type CliOpts struct {
json bool
pretty bool
fieldsOnly bool
}
func main() {
opts := CliOpts{}
flag.BoolVar(&opts.json, "json", false, "set true for JSONFormatter")
flag.BoolVar(&opts.pretty, "pretty", false, "set true to make json pretty")
flag.BoolVar(&opts.fieldsOnly, "fieldsOnly", false, "set true to make text formatter fields only")
flag.Parse()
if opts.json {
SetFormatter(&JSONFormatter{PrettyPrint: opts.pretty})
}
if opts.fieldsOnly {
SetFormatter(&TextFormatter{HasFieldsOnly: true})
}
var debug = Spawn("main")
var sibling = Spawn("sibling")
for {
// app-name:main ....
debug.WithField("key", "value").Log("sending mail")
debug.Log(func() string { return "sending mail" })
debug.Log("send email to %s", "[email protected]")
debug.Log("send email to %s", "[email protected]")
debug.Log("send email to %s", "[email protected]")
debug.Error("oh noes")
debug.Spawn("child").Log("hi from child")
sibling.Spawn("a").Log("hi")
sibling.Spawn("b").Log("hi")
sibling.Spawn("b").Error("sad")
time.Sleep(500 * time.Millisecond)
}
}