Logger.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "Logger.h"
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <time.h>
  5. #include <3ds/console.h>
  6. using namespace WalrusRPG;
  7. namespace
  8. {
  9. PrintConsole *console;
  10. // TODO : Find a better name
  11. /**
  12. * Prints the timestamp and the message category/type.
  13. */
  14. void print_premessage(const char *type)
  15. {
  16. char date_buffer[256];
  17. time_t now = time(0);
  18. strftime(date_buffer, 256, "%H:%M:%S", localtime(&now));
  19. printf("%s %5s : ", date_buffer, type);
  20. }
  21. }
  22. // NOTE : I really wish there would be a better way to handle these stupid va_lists. So
  23. // much redundant code...
  24. void Logger::init()
  25. {
  26. console = consoleInit(GFX_BOTTOM, NULL);
  27. }
  28. void Logger::log(const char *fmt, ...)
  29. {
  30. print_premessage(" [LOG]");
  31. va_list args;
  32. va_start(args, fmt);
  33. vprintf(fmt, args);
  34. va_end(args);
  35. puts("");
  36. }
  37. void Logger::debug(const char *fmt, ...)
  38. {
  39. print_premessage("[DEBUG]");
  40. va_list args;
  41. va_start(args, fmt);
  42. vprintf(fmt, args);
  43. va_end(args);
  44. puts("");
  45. }
  46. void Logger::warn(const char *fmt, ...)
  47. {
  48. print_premessage(" [WARN]");
  49. va_list args;
  50. va_start(args, fmt);
  51. vprintf(fmt, args);
  52. va_end(args);
  53. puts("");
  54. }
  55. void Logger::error(const char *fmt, ...)
  56. {
  57. print_premessage("[ERROR]");
  58. va_list args;
  59. va_start(args, fmt);
  60. vprintf(fmt, args);
  61. va_end(args);
  62. puts("");
  63. }