-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathlogger.go
63 lines (54 loc) · 1.37 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
56
57
58
59
60
61
62
63
// Copyright 2020 InfluxData, Inc. All rights reserved.
// Use of this source code is governed by MIT
// license that can be found in the LICENSE file.
package log
import (
"fmt"
"log"
)
// Logger provides filtered and categorized logging API.
// It logs to standard logger, only errors by default
type Logger struct {
debugLevel uint
}
// SetDebugLevel to filter log messages. Each level mean to log all categories bellow
// 0 errors , 1 - warning, 2 - info, 3 - debug
func (l *Logger) SetDebugLevel(debugLevel uint) {
l.debugLevel = debugLevel
}
func (l *Logger) Debugf(format string, v ...interface{}) {
if l.debugLevel > 2 {
log.Print("[D]! ", fmt.Sprintf(format, v...))
}
}
func (l *Logger) Debug(msg string) {
if l.debugLevel > 2 {
log.Print("[D]! ", msg)
}
}
func (l *Logger) Infof(format string, v ...interface{}) {
if l.debugLevel > 1 {
log.Print("[I]! ", fmt.Sprintf(format, v...))
}
}
func (l *Logger) Info(msg string) {
if l.debugLevel > 1 {
log.Print("[I]! ", msg)
}
}
func (l *Logger) Warnf(format string, v ...interface{}) {
if l.debugLevel > 0 {
log.Print("[W]! ", fmt.Sprintf(format, v...))
}
}
func (l *Logger) Warn(msg string) {
if l.debugLevel > 0 {
log.Print("[W]! ", msg)
}
}
func (l *Logger) Errorf(format string, v ...interface{}) {
log.Print("[E]! ", fmt.Sprintf(format, v...))
}
func (l *Logger) Error(msg string) {
log.Print("[E]! ", msg)
}