mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-27 23:45: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"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -34,9 +36,29 @@ func Log(verbosity int, message ...string) {
|
|||
defer mu.Unlock()
|
||||
var currentTime = time.Now()
|
||||
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 {
|
||||
fmt.Printf("[%s] %s %s \n", program, currentTime.Format(TimeFormat), currentMessage)
|
||||
}
|
||||
|
||||
if program == "netmaker" {
|
||||
currentLogs[currentMessage] = entry{
|
||||
Time: currentTime.Format("2006-01-02 15:04:05.999999999"),
|
||||
|
|
Loading…
Add table
Reference in a new issue