-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefault.go
144 lines (121 loc) · 4.59 KB
/
default.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package ligno
import (
"fmt"
"os"
)
// Log creates record and queues it for processing.
// Required parameters are level for record and event that occurred. Any
// additional parameters will be transformed to key-value pairs for record
// in order in which they were provided. There should be even number of them,
// but in case that there is on number of parameters, empty string is
// appended. Example:
// defaultLog.Log(INFO, "User logged in", "user_id", user_id, "platform", PLATFORM_NAME)
// will be translated into log record with following keys:
// {LEVEL: INFO", EVENT: "User logged in", "user_id": user_id, "platform": PLATFORM_NAME}
func Log(level Level, event string, pairs ...interface{}) {
rootLogger.Log(2, level, event, pairs...)
}
// LogCtx adds provided message in specified level.
func LogCtx(level Level, message string, ctx Ctx) {
rootLogger.LogCtx(2, level, message, ctx)
}
// Debug creates log record and queues it for processing with DEBUG level.
// Additional parameters have same semantics as in Log method.
func Debug(event string, pairs ...interface{}) {
rootLogger.Log(2, DEBUG, event, pairs...)
}
// DebugCtx logs message in DEBUG level with provided context.
func DebugCtx(message string, ctx Ctx) {
rootLogger.LogCtx(2, DEBUG, message, ctx)
}
// Info creates log record and queues it for processing with INFO level.
// Additional parameters have same semantics as in Log method.
func Info(event string, pairs ...interface{}) {
rootLogger.Log(2, INFO, event, pairs...)
}
// InfoCtx logs message in INFO level with provided context.
func InfoCtx(message string, ctx Ctx) {
rootLogger.LogCtx(2, INFO, message, ctx)
}
// Warning creates log record and queues it for processing with WARNING level.
// Additional parameters have same semantics as in Log method.
func Warning(event string, pairs ...interface{}) {
rootLogger.Log(2, WARNING, event, pairs...)
}
// WarningCtx logs message in WARNING level with provided context.
func WarningCtx(message string, ctx Ctx) {
rootLogger.LogCtx(2, WARNING, message, ctx)
}
// Error creates log record and queues it for processing with ERROR level.
// Additional parameters have same semantics as in Log method.
func Error(event string, pairs ...interface{}) {
rootLogger.Log(2, ERROR, event, pairs...)
}
// ErrorCtx logs message in ERROR level with provided context.
func ErrorCtx(message string, ctx Ctx) {
rootLogger.LogCtx(2, ERROR, message, ctx)
}
// Critical creates log record and queues it for processing with CRITICAL level.
// Additional parameters have same semantics as in Log method.
func Critical(event string, pairs ...interface{}) {
rootLogger.Log(2, CRITICAL, event, pairs...)
}
// CriticalCtx logs message in CRITICAL level with provided context.
func CriticalCtx(message string, ctx Ctx) {
rootLogger.LogCtx(2, CRITICAL, message, ctx)
}
// Printf formats message according to stdlib rules and logs it in INFO level.
func Printf(format string, v ...interface{}) {
rootLogger.Log(2, INFO, fmt.Sprintf(format, v...))
}
// Print formats message according to stdlib rules and logs it in INFO level.
func Print(v ...interface{}) {
rootLogger.Log(2, INFO, fmt.Sprint(v...))
}
// Println formats message according to stdlib rules and logs it in INFO level.
func Println(v ...interface{}) {
rootLogger.Log(2, INFO, fmt.Sprintln(v...))
}
// Fatal formats message according to stdlib rules, logs it in CRITICAL level
// and exists application.
func Fatal(v ...interface{}) {
rootLogger.Log(2, CRITICAL, fmt.Sprint(v...))
os.Exit(1)
}
// Fatalf formats message according to stdlib rules, logs it in CRITICAL level
// and exists application.
func Fatalf(format string, v ...interface{}) {
rootLogger.Log(2, CRITICAL, fmt.Sprintf(format, v...))
os.Exit(1)
}
// Fatalln formats message according to stdlib rules, logs it in CRITICAL level
// and exists application.
func Fatalln(v ...interface{}) {
rootLogger.Log(2, CRITICAL, fmt.Sprintln(v...))
os.Exit(1)
}
// Panic formats message according to stdlib rules, logs it in CRITICAL level
// and panics.
func Panic(v ...interface{}) {
s := fmt.Sprint(v...)
rootLogger.Log(2, CRITICAL, s)
panic(s)
}
// Panicf formats message according to stdlib rules, logs it in CRITICAL level
// and panics.
func Panicf(format string, v ...interface{}) {
s := fmt.Sprintf(format, v...)
rootLogger.Log(2, CRITICAL, s)
panic(s)
}
// Panicln formats message according to stdlib rules, logs it in CRITICAL level
// and panics.
func Panicln(v ...interface{}) {
s := fmt.Sprintln(v...)
rootLogger.Log(2, CRITICAL, s)
panic(s)
}
// SetHandler sets new handler for default logger.
func SetHandler(handler Handler) {
rootLogger.SetHandler(handler)
}