forked from segmentio/analytics-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
55 lines (43 loc) · 1.54 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
47
48
49
50
51
52
53
54
55
package analytics
import (
"log"
"os"
)
// Logger can be used to define where the analytics client logs are written.
type Logger interface {
// Analytics clients call this method to log regular messages about the
// operations they perform.
// Messages logged by this method are usually tagged with an `INFO` log
// level in common logging libraries.
Logf(format string, args ...interface{})
// Analytics clients call this method to log errors they encounter while
// sending events to the backend servers.
// Messages logged by this method are usually tagged with an `ERROR` log
// level in common logging libraries.
Errorf(format string, args ...interface{})
}
// StdLogger instantiate an object that statisfies the analytics.Logger
// interface and send logs to standard logger passed as argument.
func StdLogger(logger *log.Logger) Logger {
return stdLogger{
logger: logger,
}
}
type stdLogger struct {
logger *log.Logger
}
func (l stdLogger) Logf(format string, args ...interface{}) {
l.logger.Printf("INFO: "+format, args...)
}
func (l stdLogger) Errorf(format string, args ...interface{}) {
l.logger.Printf("ERROR: "+format, args...)
}
func newDefaultLogger() Logger {
return StdLogger(log.New(os.Stderr, "segment ", log.LstdFlags))
}
// DiscardLogger discards all log messages supplied to it.
type DiscardLogger struct{}
// Logf does nothing for DiscardLogger.
func (l DiscardLogger) Logf(format string, args ...interface{}) {}
// Errorf does nothing for DiscardLogger.
func (l DiscardLogger) Errorf(format string, args ...interface{}) {}