Logger.c 729 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "core/utils/Logger.h"
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. CoreLogLevel coreLogLevel = CORE_LOG_DEBUG;
  5. const char* coreGetShortFileName(const char* s) {
  6. const char* r = s;
  7. while(*s != '\0') {
  8. if(*(s++) == '/') {
  9. r = s;
  10. }
  11. }
  12. return r;
  13. }
  14. void coreLog(CoreLogLevel l, const char* file, int line, const char* prefix,
  15. const char* tag, const char* format, ...) {
  16. if(coreLogLevel < l) {
  17. return;
  18. }
  19. file = coreGetShortFileName(file);
  20. fputs(prefix, stdout);
  21. fputs(tag, stdout);
  22. printf("%s:%d | ", file, line);
  23. va_list args;
  24. va_start(args, format);
  25. vprintf(format, args);
  26. va_end(args);
  27. puts(CORE_TERMINAL_RESET);
  28. }