-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
104 lines (84 loc) · 2.49 KB
/
Copy pathlogger.go
File metadata and controls
104 lines (84 loc) · 2.49 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cloudlog
import (
"fmt"
"log"
"cloud.google.com/go/logging"
)
// Logger log information to Stackdrive console
type Logger struct {
logger *logging.Logger
local bool
}
// NewLogger constructs and returns a new logger object
func NewLogger(client *logging.Client, name string) *Logger {
return &Logger{logger: client.Logger(name), local: false}
}
func (l *Logger) EnableLocal(flag bool) {
l.local = flag
}
func (l *Logger) output(payload string, severity logging.Severity) {
e := logging.Entry{
Payload: payload,
Severity: severity,
}
l.logger.Log(e)
if l.local {
log.Printf("%v: %v", severity.String(), payload)
}
}
// Debug logs the payload
func (l *Logger) Debug(payload string) {
l.output(payload, logging.Debug)
}
// Debugf formats according to a format specifier and logs it
func (l *Logger) Debugf(format string, v ...interface{}) {
l.Debug(fmt.Sprintf(format, v...))
}
// Info logs the payload
func (l *Logger) Info(payload string) {
l.output(payload, logging.Info)
}
// Infof formats according to a format specifier and logs it
func (l *Logger) Infof(format string, v ...interface{}) {
l.Info(fmt.Sprintf(format, v...))
}
// Warning logs the payload
func (l *Logger) Warning(payload string) {
l.output(payload, logging.Warning)
}
// Warningf formats according to a format specifier and logs it
func (l *Logger) Warningf(format string, v ...interface{}) {
l.Warning(fmt.Sprintf(format, v...))
}
// Error logs the payload
func (l *Logger) Error(payload string) {
l.output(payload, logging.Error)
}
// Errorf formats according to a format specifier and logs it
func (l *Logger) Errorf(format string, v ...interface{}) {
l.Error(fmt.Sprintf(format, v...))
}
// Critical logs the payload
func (l *Logger) Critical(payload string) {
l.output(payload, logging.Critical)
}
// Criticalf formats according to a format specifier and logs it
func (l *Logger) Criticalf(format string, v ...interface{}) {
l.Critical(fmt.Sprintf(format, v...))
}
// Alert logs the payload
func (l *Logger) Alert(payload string) {
l.output(payload, logging.Alert)
}
// Alertf formats according to a format specifier and logs it
func (l *Logger) Alertf(format string, v ...interface{}) {
l.Alert(fmt.Sprintf(format, v...))
}
// Emergency logs the payload
func (l *Logger) Emergency(payload string) {
l.output(payload, logging.Emergency)
}
// Emergencyf formats according to a format specifier and logs it
func (l *Logger) Emergencyf(format string, v ...interface{}) {
l.Emergency(fmt.Sprintf(format, v...))
}