New example : Custom Logging

This commit is contained in:
Per Hultqvist 2024-10-15 16:10:41 +02:00
parent 4e4f18a37c
commit 10a7b71ee0

View file

@ -0,0 +1,49 @@
package main
import (
"fmt"
"time"
rl "github.com/gen2brain/raylib-go/raylib"
)
const (
screenWidth = 800
screenHeight = 450
)
func main() {
// Set custom logger
rl.SetTraceLogCallback(customLog)
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Custom Logging")
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("Check the console output to see the custom logger in action!", 60, 200, 20, rl.LightGray)
rl.EndDrawing()
}
rl.CloseWindow()
}
// Custom logging function
func customLog(msgType int, text string) {
now := time.Now()
switch rl.TraceLogLevel(msgType) {
case rl.LogInfo:
fmt.Println("[INFO] : ", now, text)
case rl.LogError:
fmt.Println("[ERROR] : ", now, text)
case rl.LogWarning:
fmt.Println("[WARNING] : ", now, text)
case rl.LogDebug:
fmt.Println("[DEBUG] : ", now, text)
default:
fmt.Println("[UNKNOWN] : ", now, text)
}
}