-
Notifications
You must be signed in to change notification settings - Fork 51
/
logger.go
46 lines (38 loc) · 1.06 KB
/
logger.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
package producer
import (
"fmt"
"log"
"strings"
)
// Logger represents a simple interface used by kinesis-producer to handle logging
type Logger interface {
Info(msg string, values ...LogValue)
Error(msg string, err error, values ...LogValue)
}
// LogValue represents a key:value pair used by the Logger interface
type LogValue struct {
Name string
Value interface{}
}
func (v LogValue) String() string {
return fmt.Sprintf(" %s=%s", v.Name, v.Value)
}
// StdLogger implements the Logger interface using standard library loggers
type StdLogger struct {
Logger *log.Logger
}
// Info prints log message
func (l *StdLogger) Info(msg string, values ...LogValue) {
l.Logger.Print(msg, l.valuesToString(values...))
}
// Error prints log message
func (l *StdLogger) Error(msg string, err error, values ...LogValue) {
l.Logger.Print(msg, l.valuesToString(values...), err)
}
func (l *StdLogger) valuesToString(values ...LogValue) string {
parts := make([]string, len(values))
for i, v := range values {
parts[i] = fmt.Sprint(v)
}
return strings.Join(parts, ", ")
}