-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1.02 KB
/
main.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
52
package main
import (
"math/rand"
"sync"
"time"
"github.com/danbrakeley/frog"
)
func main() {
log := frog.New(frog.Auto)
defer log.Close()
log.Info("Spawning example threads...", frog.Int("count", 3))
time.Sleep(time.Second)
wg := new(sync.WaitGroup)
count := 3
wg.Add(count)
for i := 0; i < count; i++ {
thread := i
go func() {
defer wg.Done()
doWork(log, thread)
doWork(log, thread)
}()
}
time.Sleep(time.Second)
log.Info("waited for one second...")
time.Sleep(time.Second)
log.Warning("waited for two seconds...")
time.Sleep(time.Second)
log.Error("BORED OF WAITING")
wg.Wait()
log.Info("All threads done!")
}
func doWork(parent frog.Logger, n int) {
log := frog.AddAnchor(parent)
defer frog.RemoveAnchor(log)
log.Transient(" + starting...", frog.Int("thread", n))
time.Sleep(time.Duration(400*n) * time.Millisecond)
for j := 0; j <= 100; j++ {
log.Transient(" + Status", frog.Int("thread", n), frog.Int("percent", j))
time.Sleep(time.Duration(5+rand.Intn(30)) * time.Millisecond)
}
}