Skip to content

Commit 3bc2d33

Browse files
Alexandre Steinvishr
authored andcommitted
Make the Panic and the Fatal functions behave similar to the rest (#19)
1 parent 6fe1405 commit 3bc2d33

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

log/log.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const (
4141
WARN
4242
ERROR
4343
OFF
44+
panicLevel
45+
fatalLevel
4446
)
4547

4648
var (
@@ -73,6 +75,9 @@ func (l *Logger) initLevels() {
7375
l.color.Green("INFO"),
7476
l.color.Yellow("WARN"),
7577
l.color.Red("ERROR"),
78+
"",
79+
l.color.Yellow("PANIC", color.U),
80+
l.color.Red("FATAL", color.U),
7681
}
7782
}
7883

@@ -187,32 +192,32 @@ func (l *Logger) Errorj(j JSON) {
187192
}
188193

189194
func (l *Logger) Fatal(i ...interface{}) {
190-
l.Print(i...)
195+
l.log(fatalLevel, "", i...)
191196
os.Exit(1)
192197
}
193198

194199
func (l *Logger) Fatalf(format string, args ...interface{}) {
195-
l.Printf(format, args...)
200+
l.log(fatalLevel, format, args...)
196201
os.Exit(1)
197202
}
198203

199204
func (l *Logger) Fatalj(j JSON) {
200-
l.Printj(j)
205+
l.log(fatalLevel, "json", j)
201206
os.Exit(1)
202207
}
203208

204209
func (l *Logger) Panic(i ...interface{}) {
205-
l.Print(i...)
210+
l.log(panicLevel, "", i...)
206211
panic(fmt.Sprint(i...))
207212
}
208213

209214
func (l *Logger) Panicf(format string, args ...interface{}) {
210-
l.Printf(format, args...)
215+
l.log(panicLevel, format, args...)
211216
panic(fmt.Sprintf(format, args))
212217
}
213218

214219
func (l *Logger) Panicj(j JSON) {
215-
l.Printj(j)
220+
l.log(panicLevel, "json", j)
216221
panic(j)
217222
}
218223

0 commit comments

Comments
 (0)