-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
40 lines (33 loc) · 960 Bytes
/
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
package flex
import (
"fmt"
)
// Logger is implemented by the standard *log.Logger.
type Logger interface {
Output(calldepth int, s string) error
}
var logger Logger
var debug bool
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(l Logger) {
logger = l
}
// SetDebug defines whether debugging is enabled or not.
func SetDebug(enabled bool) {
debug = enabled
}
// Logf sends to the logger registered via SetLogger the string resulting
// from running format and args through Sprintf.
func Logf(format string, args ...interface{}) {
if logger != nil {
logger.Output(2, fmt.Sprintf(format, args...))
}
}
// Debugf sends to the logger registered via SetLogger the string resulting
// from running format and args through Sprintf, but only if debugging was
// enabled via SetDebug.
func Debugf(format string, args ...interface{}) {
if debug && logger != nil {
logger.Output(2, fmt.Sprintf(format, args...))
}
}