forked from SimonLangowski/trellis
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |