-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
218 lines (173 loc) · 5.73 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// Copyright (c) Jeevanandam M (https://github.com/jeevatkm)
// go-aah/log source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package log
import (
"io"
slog "log"
"aahframework.org/config.v0"
)
var dl *Logger
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger methods
//_______________________________________
// Error logs message as `ERROR`. Arguments handled in the mananer of `fmt.Print`.
func Error(v ...interface{}) {
dl.Error(v...)
}
// Errorf logs message as `ERROR`. Arguments handled in the mananer of `fmt.Printf`.
func Errorf(format string, v ...interface{}) {
dl.Errorf(format, v...)
}
// Warn logs message as `WARN`. Arguments handled in the mananer of `fmt.Print`.
func Warn(v ...interface{}) {
dl.Warn(v...)
}
// Warnf logs message as `WARN`. Arguments handled in the mananer of `fmt.Printf`.
func Warnf(format string, v ...interface{}) {
dl.Warnf(format, v...)
}
// Info logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
func Info(v ...interface{}) {
dl.Info(v...)
}
// Infof logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Infof(format string, v ...interface{}) {
dl.Infof(format, v...)
}
// Debug logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Print`.
func Debug(v ...interface{}) {
dl.Debug(v...)
}
// Debugf logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Printf`.
func Debugf(format string, v ...interface{}) {
dl.Debugf(format, v...)
}
// Trace logs message as `TRACE`. Arguments handled in the mananer of `fmt.Print`.
func Trace(v ...interface{}) {
dl.Trace(v...)
}
// Tracef logs message as `TRACE`. Arguments handled in the mananer of `fmt.Printf`.
func Tracef(format string, v ...interface{}) {
dl.Tracef(format, v...)
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger methods - Drop-in replacement
// for Go standard logger
//_______________________________________
// Print logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
func Print(v ...interface{}) {
dl.Print(v...)
}
// Printf logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Printf(format string, v ...interface{}) {
dl.Printf(format, v...)
}
// Println logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Println(v ...interface{}) {
dl.Println(v...)
}
// Fatal logs message as `FATAL` and call to os.Exit(1).
func Fatal(v ...interface{}) {
dl.Fatal(v...)
}
// Fatalf logs message as `FATAL` and call to os.Exit(1).
func Fatalf(format string, v ...interface{}) {
dl.Fatalf(format, v...)
}
// Fatalln logs message as `FATAL` and call to os.Exit(1).
func Fatalln(v ...interface{}) {
dl.Fatalln(v...)
}
// Panic logs message as `PANIC` and call to panic().
func Panic(v ...interface{}) {
dl.Panic(v...)
}
// Panicf logs message as `PANIC` and call to panic().
func Panicf(format string, v ...interface{}) {
dl.Panicf(format, v...)
}
// Panicln logs message as `PANIC` and call to panic().
func Panicln(v ...interface{}) {
dl.Panicln(v...)
}
// AddContext method to add context values into default logger.
// These context values gets logged with each log entry.
func AddContext(fields Fields) {
dl.AddContext(fields)
}
// AddHook method is to add logger hook function.
func AddHook(name string, hook HookFunc) error {
return dl.AddHook(name, hook)
}
// WithFields method to add multiple key-value pairs into log.
func WithFields(fields Fields) Loggerer {
return dl.WithFields(fields)
}
// WithField method to add single key-value into log
func WithField(key string, value interface{}) Loggerer {
return dl.WithField(key, value)
}
// Writer method returns the writer of default logger.
func Writer() io.Writer {
return dl.receiver.Writer()
}
// SetWriter method sets the given writer into logger instance.
func SetWriter(w io.Writer) {
dl.SetWriter(w)
}
// ToGoLogger method wraps the current log writer into Go Logger instance.
func ToGoLogger() *slog.Logger {
return dl.ToGoLogger()
}
// SetDefaultLogger method sets the given logger instance as default logger.
func SetDefaultLogger(l *Logger) {
dl = l
}
// SetLevel method sets log level for default logger.
func SetLevel(level string) error {
return dl.SetLevel(level)
}
// SetPattern method sets the log format pattern for default logger.
func SetPattern(pattern string) error {
return dl.SetPattern(pattern)
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger level and assertion methods
//___________________________________
// Level method returns currently enabled logging level.
func Level() string {
return dl.Level()
}
// IsLevelInfo method returns true if log level is INFO otherwise false.
func IsLevelInfo() bool {
return dl.IsLevelInfo()
}
// IsLevelError method returns true if log level is ERROR otherwise false.
func IsLevelError() bool {
return dl.IsLevelError()
}
// IsLevelWarn method returns true if log level is WARN otherwise false.
func IsLevelWarn() bool {
return dl.IsLevelWarn()
}
// IsLevelDebug method returns true if log level is DEBUG otherwise false.
func IsLevelDebug() bool {
return dl.IsLevelDebug()
}
// IsLevelTrace method returns true if log level is TRACE otherwise false.
func IsLevelTrace() bool {
return dl.IsLevelTrace()
}
// IsLevelFatal method returns true if log level is FATAL otherwise false.
func IsLevelFatal() bool {
return dl.IsLevelFatal()
}
// IsLevelPanic method returns true if log level is PANIC otherwise false.
func IsLevelPanic() bool {
return dl.IsLevelPanic()
}
func init() {
cfg, _ := config.ParseString("log { }")
dl, _ = New(cfg)
}