From 10a7b71ee0cf1a1ff94c39bbd409662e45db6e71 Mon Sep 17 00:00:00 2001 From: Per Hultqvist Date: Tue, 15 Oct 2024 16:10:41 +0200 Subject: [PATCH] New example : Custom Logging --- examples/core/custom_logging/main.go | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/core/custom_logging/main.go diff --git a/examples/core/custom_logging/main.go b/examples/core/custom_logging/main.go new file mode 100644 index 0000000..785590e --- /dev/null +++ b/examples/core/custom_logging/main.go @@ -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) + } +}