diff options
Diffstat (limited to 'llog')
| -rw-r--r-- | llog/llog.go | 71 |
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) +} |
