Add TraceLog
This commit is contained in:
parent
7cd40090ef
commit
7132237dcd
2 changed files with 112 additions and 0 deletions
38
raylib/utils.go
Normal file
38
raylib/utils.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// +build !android
|
||||||
|
|
||||||
|
package raylib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Log message types
|
||||||
|
const (
|
||||||
|
LogInfo = iota
|
||||||
|
LogError
|
||||||
|
LogWarning
|
||||||
|
LogDebug
|
||||||
|
)
|
||||||
|
|
||||||
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
|
func TraceLog(msgType int, text string, v ...interface{}) {
|
||||||
|
switch msgType {
|
||||||
|
case LogInfo:
|
||||||
|
fmt.Printf("INFO: "+text+"\n", v...)
|
||||||
|
case LogError:
|
||||||
|
fmt.Printf("ERROR: "+text+"\n", v...)
|
||||||
|
os.Exit(1)
|
||||||
|
case LogWarning:
|
||||||
|
fmt.Printf("WARNING: "+text+"\n", v...)
|
||||||
|
case LogDebug:
|
||||||
|
if traceDebugMsgs {
|
||||||
|
fmt.Printf("DEBUG: "+text+"\n", v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetDebug(enabled bool) {
|
||||||
|
traceDebugMsgs = enabled
|
||||||
|
}
|
74
raylib/utils_android.go
Normal file
74
raylib/utils_android.go
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// +build android
|
||||||
|
|
||||||
|
package raylib
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void logInfo(const char *msg) {
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "raylib", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logWarn(const char *msg) {
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "raylib", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logError(const char *msg) {
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, "raylib", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logDebug(const char *msg) {
|
||||||
|
__android_log_print(ANDROID_LOG_DEBUG, "raylib", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logInfo(const char *msg);
|
||||||
|
void logWarn(const char *msg);
|
||||||
|
void logError(const char *msg);
|
||||||
|
void logDebug(const char *msg);
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Log message types
|
||||||
|
const (
|
||||||
|
LogInfo = iota
|
||||||
|
LogError
|
||||||
|
LogWarning
|
||||||
|
LogDebug
|
||||||
|
)
|
||||||
|
|
||||||
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
|
func TraceLog(msgType int, text string, v ...interface{}) {
|
||||||
|
switch msgType {
|
||||||
|
case LogInfo:
|
||||||
|
msg := C.CString(fmt.Sprintf("INFO: "+text, v...))
|
||||||
|
defer C.free(unsafe.Pointer(msg))
|
||||||
|
C.logInfo(msg)
|
||||||
|
case LogError:
|
||||||
|
msg := C.CString(fmt.Sprintf("ERROR: "+text, v...))
|
||||||
|
defer C.free(unsafe.Pointer(msg))
|
||||||
|
C.logError(msg)
|
||||||
|
os.Exit(1)
|
||||||
|
case LogWarning:
|
||||||
|
msg := C.CString(fmt.Sprintf("WARNING: "+text, v...))
|
||||||
|
defer C.free(unsafe.Pointer(msg))
|
||||||
|
C.logWarn(msg)
|
||||||
|
case LogDebug:
|
||||||
|
if traceDebugMsgs {
|
||||||
|
msg := C.CString(fmt.Sprintf("DEBUG: "+text, v...))
|
||||||
|
defer C.free(unsafe.Pointer(msg))
|
||||||
|
C.logDebug(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetDebug(enabled bool) {
|
||||||
|
traceDebugMsgs = enabled
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue