Skip to content

Commit

Permalink
feat(xtrellis): add utils.DebugLog
Browse files Browse the repository at this point in the history
  • Loading branch information
xendarboh committed Sep 20, 2023
1 parent ac83abf commit 1ef0dc0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/xtrellis/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package utils

import (
"fmt"
"log"
"regexp"
"runtime"
)

var debugLogEnabled = false

func SetDebugLogEnabled(enabled bool) {
debugLogEnabled = enabled
}

func DebugLog(format string, args ...interface{}) {
if !debugLogEnabled {
return
}

// get the calling function's name, filename, and line number
pc, filename, line, _ := runtime.Caller(1)
funcname := runtime.FuncForPC(pc).Name()

// remove project root to shorten file path
re := regexp.MustCompile("(.*)/trellis/")
path := re.ReplaceAllString(filename, "")

s1 := fmt.Sprintf("🔷 %s:%s:%d", path, funcname, line)
s2 := fmt.Sprintf(format, args...)
log.Printf("%s %s", s1, s2)
}

0 comments on commit 1ef0dc0

Please sign in to comment.