-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
40 lines (34 loc) · 756 Bytes
/
debug.go
File metadata and controls
40 lines (34 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package nstd
import (
"log"
"os"
)
var debugLogger = log.New(os.Stderr, "[debug]: ", 0)
// Debug calls [log.Print] and returns true,
// so that it can be used in
//
// _ = DebugMode && nstd.Debug(...)
func Debug(v ...any) bool {
debugLogger.Print(v...)
return true
}
// Debugf calls [log.Printf] and return true,
// so that it can be used in
//
// _ = DebugMode && nstd.Debugf(...)
func Debugf(format string, v ...any) bool {
debugLogger.Printf(format, v...)
return true
}
// assert is used interanlly
func assert(condition bool, failMessage string, args ...any) bool {
if !condition {
if len(args) == 0 {
debugLogger.Print(failMessage)
} else {
debugLogger.Printf(failMessage, args...)
}
panic("Assert fails")
}
return true
}