forked from pivotal-cf/cf-redis-broker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_sink.go
55 lines (45 loc) · 951 Bytes
/
cli_sink.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
53
54
55
package log
import (
"fmt"
"io"
"os"
"strings"
"code.cloudfoundry.org/lager"
)
type lagerEntry struct {
Data map[string]interface{}
LogLevel int
Message string
Source string
Timestamp string
}
type CliSink struct {
writer io.Writer
minLogLevel lager.LogLevel
}
func NewCliSink(minLogLevel lager.LogLevel) lager.Sink {
return &CliSink{
writer: os.Stdout,
minLogLevel: minLogLevel,
}
}
func (s *CliSink) Log(format lager.LogFormat) {
if format.LogLevel < s.minLogLevel {
return
}
if format.Message == "" || format.Data == nil || format.Data["event"] == "" {
return
}
fmt.Fprintln(s.writer, prettify(format.Message, format.Data["event"]))
}
func prettify(message string, event interface{}) string {
return fmt.Sprintf(
"%15s -> %s",
splitLagerMessage(message),
event,
)
}
func splitLagerMessage(message string) string {
parts := strings.Split(message, ".")
return parts[len(parts)-1]
}