aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2022-07-27 20:14:48 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2022-07-27 20:14:48 +0200
commit84ff772ee1642c4f139605fc1a2716ce49f4b015 (patch)
treee8218a6966c90b4a2bffc2ef080049fbd060aa7c
parent33fd4442dd8297d02d284e82cf09bbfec01c705a (diff)
downloadWRMS-84ff772ee1642c4f139605fc1a2716ce49f4b015.tar.gz
WRMS-84ff772ee1642c4f139605fc1a2716ce49f4b015.zip
add simple leveled log wrapper
-rw-r--r--llog/llog.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/llog/llog.go b/llog/llog.go
new file mode 100644
index 0000000..e7fb924
--- /dev/null
+++ b/llog/llog.go
@@ -0,0 +1,71 @@
+package llog
+
+import (
+ "fmt"
+ "log"
+)
+
+type LogLevel int
+
+const (
+ l_Fatal LogLevel = iota + 1
+ l_Error
+ l_Warning
+ l_Info
+ l_Debug
+ l_DDebug
+)
+
+var Level LogLevel = l_Warning
+
+func getLevelNames() []string {
+ return []string{"Fatal", "Error", "Warning", "Info", "Debug", "DDebug"}
+}
+
+func (l LogLevel) IsValid() bool {
+ return l >= l_Fatal && l <= l_DDebug
+}
+
+func (l LogLevel) String() string {
+ if !l.IsValid() {
+ return fmt.Sprintf("LogLevel(%d)", int(l))
+ }
+
+ return getLevelNames()[l-1]
+}
+
+func Log(l LogLevel, msg string) {
+ msg = fmt.Sprintf("[%s] %s", l.String(), msg)
+
+ if l == l_Fatal {
+ log.Fatalln(msg)
+ }
+
+ if l <= Level {
+ log.Println(msg)
+ }
+}
+
+func Fatal(msg string) {
+ Log(l_Fatal, msg)
+}
+
+func Error(msg string) {
+ Log(l_Error, msg)
+}
+
+func Warning(msg string) {
+ Log(l_Warning, msg)
+}
+
+func Info(msg string) {
+ Log(l_Info, msg)
+}
+
+func Debug(msg string) {
+ Log(l_Debug, msg)
+}
+
+func DDebug(msg string) {
+ Log(l_DDebug, msg)
+}