Spaces:
Running
Running
File size: 1,134 Bytes
d669ddb |
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 |
package common
import (
"log"
"os"
)
const (
DEBUG = "DEBUG"
INFO = "INFO"
WARN = "WARN"
ERROR = "ERROR"
)
var LevelArry = [4]string{DEBUG, INFO, WARN, ERROR}
var levelMap = map[string]int{
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
}
type logger struct {
Level string
}
var Logger *logger
func NewLogger(level string) *logger {
return &logger{Level: level}
}
func (l *logger) Clone() *logger {
return &logger{Level: l.Level}
}
func (l *logger) Fatal(v ...interface{}) {
l.Info("%v", v...)
os.Exit(1)
}
func (l *logger) Print(level, format string, v ...interface{}) {
if levelMap[level] >= levelMap[l.Level] {
log.Printf("- "+level+" - "+format, v...)
}
}
func (l *logger) Println(level string, v ...interface{}) {
l.Print(level, "%v", v...)
}
func (l *logger) Debug(format string, v ...interface{}) {
l.Print(DEBUG, format, v...)
}
func (l *logger) Info(format string, v ...interface{}) {
l.Print(INFO, format, v...)
}
func (l *logger) Warn(format string, v ...interface{}) {
l.Print(WARN, format, v...)
}
func (l *logger) Error(format string, v ...interface{}) {
l.Print(ERROR, format, v...)
}
|