|
@@ -2,7 +2,6 @@ package log
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "github.com/davecgh/go-spew/spew"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"runtime"
|
|
@@ -32,41 +31,9 @@ const (
|
|
|
FATAL = 5
|
|
|
)
|
|
|
|
|
|
-// Stringer interface
|
|
|
-type Stringer interface {
|
|
|
- LogString() string
|
|
|
-}
|
|
|
-
|
|
|
-// Init logger
|
|
|
-func Init(plevel int) {
|
|
|
- level = plevel
|
|
|
- spew.Config.DisableMethods = true
|
|
|
- spew.Config.Indent = " "
|
|
|
-}
|
|
|
-
|
|
|
-// Dumpf object
|
|
|
-func Dumpf(format string, a ...interface{}) string {
|
|
|
- return spew.Sprintf(format, a...)
|
|
|
-}
|
|
|
-
|
|
|
-// Dump object
|
|
|
-func Dump(a ...interface{}) string {
|
|
|
- return spew.Sdump(a...)
|
|
|
-}
|
|
|
-
|
|
|
-func dump(a ...interface{}) []interface{} {
|
|
|
- for ai, av := range a {
|
|
|
- if avf, ok := av.(func() string); ok {
|
|
|
- a[ai] = avf()
|
|
|
- } else if avf, ok := av.(Stringer); ok {
|
|
|
- a[ai] = avf.LogString()
|
|
|
- } else if avf, ok := av.(fmt.GoStringer); ok {
|
|
|
- a[ai] = avf.GoString()
|
|
|
- } else if avf, ok := av.(fmt.Stringer); ok {
|
|
|
- a[ai] = avf.String()
|
|
|
- }
|
|
|
- }
|
|
|
- return a
|
|
|
+// IsDebugEnable func
|
|
|
+func IsDebugEnable() bool {
|
|
|
+ return level <= DEBUG
|
|
|
}
|
|
|
|
|
|
// Trace log
|
|
@@ -78,7 +45,7 @@ func Trace(a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -87,7 +54,7 @@ func Trace(a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Printf("TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -100,7 +67,7 @@ func Tracef(format string, a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -109,7 +76,7 @@ func Tracef(format string, a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Printf("TRACE: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -122,7 +89,7 @@ func Debug(a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -131,7 +98,7 @@ func Debug(a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Printf("DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -144,7 +111,7 @@ func Debugf(format string, a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -153,7 +120,7 @@ func Debugf(format string, a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Printf("DEBUG: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -166,7 +133,7 @@ func Info(a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -175,7 +142,7 @@ func Info(a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Printf("INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -188,7 +155,7 @@ func Infof(format string, a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -197,7 +164,7 @@ func Infof(format string, a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Printf("INFO: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -210,7 +177,7 @@ func Warning(a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -219,7 +186,7 @@ func Warning(a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Printf("WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -232,7 +199,7 @@ func Warningf(format string, a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -241,7 +208,7 @@ func Warningf(format string, a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Printf("WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Printf("WARN: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -254,7 +221,7 @@ func Error(a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -263,7 +230,7 @@ func Error(a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprint(a...))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -276,7 +243,7 @@ func Errorf(format string, a ...interface{}) {
|
|
|
if strings.HasSuffix(path, "/libexec/src/runtime/panic.go") {
|
|
|
_, path, line, _ := runtime.Caller(i + 1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -285,6 +252,6 @@ func Errorf(format string, a ...interface{}) {
|
|
|
}
|
|
|
_, path, line, _ := runtime.Caller(1)
|
|
|
_, file := filepath.Split(path)
|
|
|
- fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, dump(a...)...))
|
|
|
+ fmt.Fprintf(os.Stderr, "ERROR: %s %v:%v: %s\n", time.Now().Format("01:04:05.000"), file, line, fmt.Sprintf(format, a...))
|
|
|
}
|
|
|
}
|