-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbucky.go
More file actions
55 lines (44 loc) · 1 KB
/
bucky.go
File metadata and controls
55 lines (44 loc) · 1 KB
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
53
54
55
package main
import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"time"
"math/rand"
"github.com/icrowley/fake"
"fmt"
)
func RunPeriodically(c *cli.Context) error {
rand.Seed(time.Now().UTC().UnixNano())
log.SetFormatter(_makeFormatter(c.String("format")))
log.WithFields(log.Fields{
"appName": c.App.Name,
}).Info("Running periodically")
period := c.Duration("period")
messageCount := c.Uint64("count")
for {
go func() {
PrintMessages(messageCount)
}()
time.Sleep(period)
}
}
func PrintMessages(messageCount uint64) {
tNanos := time.Now().UTC().UnixNano()
for i := uint64(0); i < messageCount; i++ {
msgId := fmt.Sprintf("%d-%d", tNanos, i)
log.WithFields(log.Fields{
"type": "log",
"msgId": msgId,
}).Info(fake.SentencesN(rand.Intn(10)))
}
}
func _makeFormatter(format string) log.Formatter {
switch format {
case "text":
return &log.TextFormatter{DisableColors: true}
case "json":
return &log.JSONFormatter{}
default:
return &log.JSONFormatter{}
}
}