-
Notifications
You must be signed in to change notification settings - Fork 4
/
logger.go
45 lines (38 loc) · 1.26 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
package venom
import (
"fmt"
"log"
"time"
)
const (
TIME_FORMAT = "2006-01-02T15:04:05.999Z"
LOG_NAME = "[venom]"
)
// Logger is the interface a user must implement in order to be used by
// the LogableConfigStore.
type Logger interface {
LogWrite(level ConfigLevel, key string, val interface{})
LogRead(key string, val interface{}, bl bool)
}
// StoreLogger is Venom's default Logger.
type StoreLogger struct {
Log *log.Logger
}
// NewStoreLogger returns a Logger suitable for default use case.
func NewStoreLogger(l *log.Logger) Logger {
return &StoreLogger{
Log: l,
}
}
// LogWrite is the default logging behavior of a LoggableConfigStore on an
// action to set a value in the ConfigStore.
func (sl *StoreLogger) LogWrite(level ConfigLevel, key string, val interface{}) {
logLine := fmt.Sprintf("%s%s: writing level=%v key=%s val=%s", time.Now().UTC().Format(TIME_FORMAT), LOG_NAME, level, key, val)
sl.Log.Print(logLine)
}
// LogWrite is the default logging behavior of a LoggableConfigStore on an
// action to read a value in the ConfigStore.
func (sl *StoreLogger) LogRead(key string, val interface{}, bl bool) {
logLine := fmt.Sprintf("%s%s: reading key=%s val=%s exist=%v", time.Now().UTC().Format(TIME_FORMAT), LOG_NAME, key, val, bl)
sl.Log.Print(logLine)
}