-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.go
41 lines (36 loc) · 1.05 KB
/
log.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
// Copyright (c) 2021 Circonus, Inc. <[email protected]>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package trapmetrics
import "log"
// Logger is a generic logging interface.
type Logger interface {
Printf(fmt string, v ...interface{})
Debugf(fmt string, v ...interface{})
Infof(fmt string, v ...interface{})
Warnf(fmt string, v ...interface{})
Errorf(fmt string, v ...interface{})
}
// LogWrapper is a wrapper around Go's log.Logger.
type LogWrapper struct {
Log *log.Logger
Debug bool
}
func (lw *LogWrapper) Printf(fmt string, v ...interface{}) {
lw.Log.Printf(fmt, v...)
}
func (lw *LogWrapper) Debugf(fmt string, v ...interface{}) {
if lw.Debug {
lw.Log.Printf("[debug] "+fmt, v...)
}
}
func (lw *LogWrapper) Infof(fmt string, v ...interface{}) {
lw.Log.Printf("[info] "+fmt, v...)
}
func (lw *LogWrapper) Warnf(fmt string, v ...interface{}) {
lw.Log.Printf("[warn] "+fmt, v...)
}
func (lw *LogWrapper) Errorf(fmt string, v ...interface{}) {
lw.Log.Printf("[error] "+fmt, v...)
}