aboutsummaryrefslogtreecommitdiff
path: root/llog/llog.go
blob: e7fb924c640b32724c378de253780dd125990c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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)
}