From 548575b4a75da9a3bfcff98fa15b83cb4bee26ed Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 10 Dec 2020 22:09:16 -0500 Subject: [PATCH] Add Fatal and Panic --- README.md | 6 ++++++ slog.go | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 131e217..f5a76ca 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ Also provided are a few simple methods for handling returned `error` variables, func Error(format string, v ...interface{}) Error will log with a ERROR prefix + func Fatal(format string, v ...interface{}) + Fatal will log with a ERROR prefix followed by exit(1) + func FatalOnErr(err error, format string, v ...interface{}) FatalOnErr if error provided, will log out details of an error and exi @@ -50,6 +53,9 @@ Also provided are a few simple methods for handling returned `error` variables, func Log(format string, v ...interface{}) Log formats logs directly to the main logger + func Panic(format string, v ...interface{}) + Panic will log with a ERROR prefix followed by panic() + func PanicOnErr(err error, format string, v ...interface{}) PanicOnErr if error provided, will log out details of an error and exi diff --git a/slog.go b/slog.go index 94db415..ef47347 100644 --- a/slog.go +++ b/slog.go @@ -54,6 +54,14 @@ func Log(format string, v ...interface{}) { log.Printf(format, v...) } +// Debug will log with a DEBUG prefix if DebugLevel is set +func Debug(format string, v ...interface{}) { + if !DebugLevel { + return + } + LoggerDebug.Printf(format, v...) +} + // Info formats logs with an INFO prefix func Info(format string, v ...interface{}) { LoggerInfo.Printf(format, v...) @@ -69,12 +77,14 @@ func Error(format string, v ...interface{}) { LoggerError.Printf(format, v...) } -// Debug will log with a DEBUG prefix if DebugLevel is set -func Debug(format string, v ...interface{}) { - if !DebugLevel { - return - } - LoggerDebug.Printf(format, v...) +// Fatal will log with a ERROR prefix followed by exit(1) +func Fatal(format string, v ...interface{}) { + LoggerError.Fatalf(format, v...) +} + +// Panic will log with a ERROR prefix followed by panic() +func Panic(format string, v ...interface{}) { + LoggerError.Panicf(format, v...) } // WarnOnErr if error provided, will provide a warning if an error is provided