forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
43 lines (35 loc) · 885 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
41
42
43
package util
import (
"io"
"k8s.io/klog"
"github.com/openshift/library-go/pkg/serviceability"
)
// NewGLogWriterV returns a new Writer that delegates to `klog.Info` at the
// desired level of verbosity
func NewGLogWriterV(level int) io.Writer {
return &gLogWriter{
level: klog.Level(level),
}
}
// gLogWriter is a Writer that writes by delegating to `klog.Info`
type gLogWriter struct {
// level is the default level to log at
level klog.Level
}
func (w *gLogWriter) Write(p []byte) (n int, err error) {
if klog.V(w.level) {
klog.InfoDepth(2, string(p))
}
return len(p), nil
}
// InitLogrus sets the logrus trace level based on the glog trace level.
func InitLogrus() {
switch {
case bool(klog.V(4)):
serviceability.InitLogrus("DEBUG")
case bool(klog.V(2)):
serviceability.InitLogrus("INFO")
case bool(klog.V(0)):
serviceability.InitLogrus("WARN")
}
}