-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_logger.go
81 lines (64 loc) · 2.4 KB
/
console_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package logutil
import (
"fmt"
"github.com/Ciyfly/vitess/go/vt/log"
)
// ConsoleLogger is a Logger that uses glog directly to log, at the right level.
//
// Note that methods on ConsoleLogger must use pointer receivers,
// because otherwise an autogenerated conversion method will be inserted in the
// call stack when ConsoleLogger is used via TeeLogger, making the log depth
// incorrect.
type ConsoleLogger struct{}
// NewConsoleLogger returns a simple ConsoleLogger.
func NewConsoleLogger() *ConsoleLogger {
return &ConsoleLogger{}
}
// Infof is part of the Logger interface
func (cl *ConsoleLogger) Infof(format string, v ...interface{}) {
cl.InfoDepth(1, fmt.Sprintf(format, v...))
}
// Warningf is part of the Logger interface
func (cl *ConsoleLogger) Warningf(format string, v ...interface{}) {
cl.WarningDepth(1, fmt.Sprintf(format, v...))
}
// Errorf is part of the Logger interface
func (cl *ConsoleLogger) Errorf(format string, v ...interface{}) {
cl.ErrorDepth(1, fmt.Sprintf(format, v...))
}
// Errorf2 is part of the Logger interface
func (cl *ConsoleLogger) Errorf2(err error, format string, v ...interface{}) {
cl.ErrorDepth(1, fmt.Sprintf(format+": %+v", append(v, err)))
}
// Error is part of the Logger interface
func (cl *ConsoleLogger) Error(err error) {
cl.ErrorDepth(1, fmt.Sprintf("%+v", err))
}
// Printf is part of the Logger interface
func (cl *ConsoleLogger) Printf(format string, v ...interface{}) {
fmt.Printf(format, v...)
}
// InfoDepth is part of the Logger interface.
func (cl *ConsoleLogger) InfoDepth(depth int, s string) {
log.InfoDepth(1+depth, s)
}
// WarningDepth is part of the Logger interface.
func (cl *ConsoleLogger) WarningDepth(depth int, s string) {
log.WarningDepth(1+depth, s)
}
// ErrorDepth is part of the Logger interface.
func (cl *ConsoleLogger) ErrorDepth(depth int, s string) {
log.ErrorDepth(1+depth, s)
}