You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Custom logging
  4. *
  5. * Example originally created with raylib 2.5, last time updated with raylib 2.5
  6. *
  7. * Example contributed by Pablo Marcos Oltra (@pamarcos) and reviewed by Ramon Santamaria (@raysan5)
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2018-2024 Pablo Marcos Oltra (@pamarcos) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. #include <stdio.h> // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen()
  17. #include <time.h> // Required for: time_t, tm, time(), localtime(), strftime()
  18. // Custom logging function
  19. void CustomLog(int msgType, const char *text, va_list args)
  20. {
  21. char timeStr[64] = { 0 };
  22. time_t now = time(NULL);
  23. struct tm *tm_info = localtime(&now);
  24. strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
  25. printf("[%s] ", timeStr);
  26. switch (msgType)
  27. {
  28. case LOG_INFO: printf("[INFO] : "); break;
  29. case LOG_ERROR: printf("[ERROR]: "); break;
  30. case LOG_WARNING: printf("[WARN] : "); break;
  31. case LOG_DEBUG: printf("[DEBUG]: "); break;
  32. default: break;
  33. }
  34. vprintf(text, args);
  35. printf("\n");
  36. }
  37. //------------------------------------------------------------------------------------
  38. // Program main entry point
  39. //------------------------------------------------------------------------------------
  40. int main(void)
  41. {
  42. // Initialization
  43. //--------------------------------------------------------------------------------------
  44. const int screenWidth = 800;
  45. const int screenHeight = 450;
  46. // Set custom logger
  47. SetTraceLogCallback(CustomLog);
  48. InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
  49. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  50. //--------------------------------------------------------------------------------------
  51. // Main game loop
  52. while (!WindowShouldClose()) // Detect window close button or ESC key
  53. {
  54. // Update
  55. //----------------------------------------------------------------------------------
  56. // TODO: Update your variables here
  57. //----------------------------------------------------------------------------------
  58. // Draw
  59. //----------------------------------------------------------------------------------
  60. BeginDrawing();
  61. ClearBackground(RAYWHITE);
  62. DrawText("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY);
  63. EndDrawing();
  64. //----------------------------------------------------------------------------------
  65. }
  66. // De-Initialization
  67. //--------------------------------------------------------------------------------------
  68. CloseWindow(); // Close window and OpenGL context
  69. //--------------------------------------------------------------------------------------
  70. return 0;
  71. }