Skip to content

Commit 05b905f

Browse files
committed
level fatal, panic exported and level check method added
1 parent 4120f94 commit 05b905f

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

console_receiver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var (
2020
// ANSI color codes
2121
resetColor = []byte("\033[0m")
2222
levelToColor = [][]byte{
23-
levelFatal: []byte("\033[0;31m"), // red
24-
levelPanic: []byte("\033[0;31m"), // red
23+
LevelFatal: []byte("\033[0;31m"), // red
24+
LevelPanic: []byte("\033[0;31m"), // red
2525
LevelError: []byte("\033[0;31m"), // red
2626
LevelWarn: []byte("\033[0;33m"), // yellow
2727
LevelInfo: []byte("\033[0;37m"), // white

default.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ func IsLevelTrace() bool {
202202
return dl.IsLevelTrace()
203203
}
204204

205+
// IsLevelFatal method returns true if log level is FATAL otherwise false.
206+
func IsLevelFatal() bool {
207+
return dl.IsLevelFatal()
208+
}
209+
210+
// IsLevelPanic method returns true if log level is PANIC otherwise false.
211+
func IsLevelPanic() bool {
212+
return dl.IsLevelPanic()
213+
}
214+
205215
func init() {
206216
cfg, _ := config.ParseString("log { }")
207217
dl, _ = New(cfg)

default_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func TestDefaultLogger(t *testing.T) {
4545
assert.False(t, IsLevelInfo())
4646
assert.False(t, IsLevelWarn())
4747
assert.False(t, IsLevelTrace())
48+
assert.False(t, IsLevelFatal())
49+
assert.False(t, IsLevelPanic())
4850

4951
exit = func(code int) {}
5052
Fatal("fatal msg 1")

entry.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,37 @@ func (e *Entry) Println(v ...interface{}) {
160160

161161
// Fatal logs message as `FATAL` and call to os.Exit(1).
162162
func (e *Entry) Fatal(v ...interface{}) {
163-
e.output(levelFatal, fmt.Sprint(v...))
163+
e.output(LevelFatal, fmt.Sprint(v...))
164164
exit(1)
165165
}
166166

167167
// Fatalf logs message as `FATAL` and call to os.Exit(1).
168168
func (e *Entry) Fatalf(format string, v ...interface{}) {
169-
e.output(levelFatal, fmt.Sprintf(format, v...))
169+
e.output(LevelFatal, fmt.Sprintf(format, v...))
170170
exit(1)
171171
}
172172

173173
// Fatalln logs message as `FATAL` and call to os.Exit(1).
174174
func (e *Entry) Fatalln(v ...interface{}) {
175-
e.output(levelFatal, fmt.Sprint(v...))
175+
e.output(LevelFatal, fmt.Sprint(v...))
176176
exit(1)
177177
}
178178

179179
// Panic logs message as `PANIC` and call to panic().
180180
func (e *Entry) Panic(v ...interface{}) {
181-
e.output(levelPanic, fmt.Sprint(v...))
181+
e.output(LevelPanic, fmt.Sprint(v...))
182182
panic(e)
183183
}
184184

185185
// Panicf logs message as `PANIC` and call to panic().
186186
func (e *Entry) Panicf(format string, v ...interface{}) {
187-
e.output(levelPanic, fmt.Sprintf(format, v...))
187+
e.output(LevelPanic, fmt.Sprintf(format, v...))
188188
panic(e)
189189
}
190190

191191
// Panicln logs message as `PANIC` and call to panic().
192192
func (e *Entry) Panicln(v ...interface{}) {
193-
e.output(levelPanic, fmt.Sprint(v...))
193+
e.output(LevelPanic, fmt.Sprint(v...))
194194
panic(e)
195195
}
196196

log.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type HookFunc func(e Entry)
4141

4242
// Log Level definition
4343
const (
44-
levelFatal level = iota
45-
levelPanic
44+
LevelFatal level = iota
45+
LevelPanic
4646
LevelError
4747
LevelWarn
4848
LevelInfo
@@ -467,6 +467,16 @@ func (l *Logger) IsLevelTrace() bool {
467467
return l.level == LevelTrace
468468
}
469469

470+
// IsLevelFatal method returns true if log level is FATAL otherwise false.
471+
func (l *Logger) IsLevelFatal() bool {
472+
return l.level == LevelFatal
473+
}
474+
475+
// IsLevelPanic method returns true if log level is PANIC otherwise false.
476+
func (l *Logger) IsLevelPanic() bool {
477+
return l.level == LevelPanic
478+
}
479+
470480
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
471481
// Unexported methods
472482
//___________________________________
@@ -478,7 +488,6 @@ func (l *Logger) output(e *Entry) {
478488
l.receiver.Log(e)
479489

480490
// Execute logger hooks
481-
fmt.Println("Hooks:", l.hooks)
482491
go l.executeHooks(*e)
483492
}
484493

util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
var (
1616
levelNameToLevel = map[string]level{
17-
"FATAL": levelFatal,
18-
"PANIC": levelPanic,
17+
"FATAL": LevelFatal,
18+
"PANIC": LevelPanic,
1919
"ERROR": LevelError,
2020
"WARN": LevelWarn,
2121
"INFO": LevelInfo,
@@ -24,8 +24,8 @@ var (
2424
}
2525

2626
levelToLevelName = map[level]string{
27-
levelFatal: "FATAL",
28-
levelPanic: "PANIC",
27+
LevelFatal: "FATAL",
28+
LevelPanic: "PANIC",
2929
LevelError: "ERROR",
3030
LevelWarn: "WARN",
3131
LevelInfo: "INFO",

0 commit comments

Comments
 (0)