mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-08 04:46:45 +08:00
GRA-414: introduced new log level 4 for runtime caller info
This commit is contained in:
parent
8e70a254fb
commit
9dd1afc319
1 changed files with 22 additions and 0 deletions
|
@ -4,7 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -34,9 +36,29 @@ func Log(verbosity int, message ...string) {
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
var currentTime = time.Now()
|
var currentTime = time.Now()
|
||||||
var currentMessage = MakeString(" ", message...)
|
var currentMessage = MakeString(" ", message...)
|
||||||
|
|
||||||
|
if int32(verbosity) >= 4 {
|
||||||
|
pc, file, line, ok := runtime.Caller(1)
|
||||||
|
if !ok {
|
||||||
|
file = "?"
|
||||||
|
line = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn := runtime.FuncForPC(pc)
|
||||||
|
var fnName string
|
||||||
|
if fn == nil {
|
||||||
|
fnName = "?()"
|
||||||
|
} else {
|
||||||
|
fnName = strings.TrimLeft(filepath.Ext(fn.Name()), ".") + "()"
|
||||||
|
}
|
||||||
|
currentMessage = fmt.Sprintf("[%s-%d] %s: %s",
|
||||||
|
filepath.Base(file), line, fnName, currentMessage)
|
||||||
|
}
|
||||||
|
|
||||||
if int32(verbosity) <= getVerbose() && getVerbose() >= 0 {
|
if int32(verbosity) <= getVerbose() && getVerbose() >= 0 {
|
||||||
fmt.Printf("[%s] %s %s \n", program, currentTime.Format(TimeFormat), currentMessage)
|
fmt.Printf("[%s] %s %s \n", program, currentTime.Format(TimeFormat), currentMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
if program == "netmaker" {
|
if program == "netmaker" {
|
||||||
currentLogs[currentMessage] = entry{
|
currentLogs[currentMessage] = entry{
|
||||||
Time: currentTime.Format("2006-01-02 15:04:05.999999999"),
|
Time: currentTime.Format("2006-01-02 15:04:05.999999999"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue