-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
65 lines (52 loc) · 1.77 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package log
import (
"io"
"log"
"github.com/kyfk/log/level"
)
var defaultLogger = New()
// SetMinLevel sets minumum logging level to the default logger.
func SetMinLevel(lv level.Level) {
defaultLogger.level = lv
}
// SetFormat sets the format of message output to the default logger.
func SetFormat(fm formatter) {
defaultLogger.formatter = fm
}
// SetMetadata sets metadata to default logger.
// If you use some querying service for searching specific logs like BigQuery,
// CloudWatch Logs Insight, Elasticsearch and other more, SetMetadata can be used to
// set additional information to be able to search for conveniently.
// For instance, HTTP Request ID, the id of user signed in, EC2 instance-id and other more.
func SetMetadata(md map[string]interface{}) {
defaultLogger.metadata = md
}
// SetOutput sets io.Writer as destination of logging message to the default logger.
func SetOutput(out io.Writer) {
defaultLogger.logger = log.New(out, "", 0)
}
// SetStdLogger sets StdLogger that is used output message to the default logger.
func SetStdLogger(lg *log.Logger) {
defaultLogger.logger = lg
}
// SetFlattenMetadata sets the flag if metadata is going to be flattened.
// If the flag is put on, metadata is going to be flattened in output
func SetFlattenMetadata(b bool) {
defaultLogger.flattenMetadata = b
}
// Debug logs a message at level Debug on the default logger.
func Debug(v ...interface{}) {
defaultLogger.Debug(v...)
}
// Info logs a message at level Info on the default logger.
func Info(v ...interface{}) {
defaultLogger.Info(v...)
}
// Warn logs a message at level Warn on the default logger.
func Warn(v ...interface{}) {
defaultLogger.Warn(v...)
}
// Error logs a message at level Error on the default logger.
func Error(err error) {
defaultLogger.Error(err)
}