Logger.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef LOGGER_H
  2. #define LOGGER_H
  3. #include "utils/StringBuffer.h"
  4. namespace Logger {
  5. enum Level { NONE, ERROR, WARNING, INFO, DEBUG };
  6. extern Level level;
  7. template<int N>
  8. void error(const StringBuffer<N>& s) {
  9. #if LOG_LEVEL >= 1
  10. if(level >= ERROR) {
  11. std::cout << "\33[1;31m[ERROR] " << s << "\33[39;49m\n";
  12. }
  13. #else
  14. (void)s;
  15. #endif
  16. }
  17. template<int N>
  18. void warn(const StringBuffer<N>& s) {
  19. #if LOG_LEVEL >= 2
  20. if(level >= WARNING) {
  21. std::cout << "\33[1;33m[WARNING] " << s << "\33[39;49m\n";
  22. }
  23. #else
  24. (void)s;
  25. #endif
  26. }
  27. template<int N>
  28. void info(const StringBuffer<N>& s) {
  29. #if LOG_LEVEL >= 3
  30. if(level >= INFO) {
  31. std::cout << "\33[1;37m[INFO] " << s << "\33[39;49m\n";
  32. }
  33. #else
  34. (void)s;
  35. #endif
  36. }
  37. template<int N>
  38. void debug(const StringBuffer<N>& s) {
  39. #if LOG_LEVEL >= 4
  40. if(level >= DEBUG) {
  41. std::cout << "\33[1;32m[DEBUG] " << s << "\33[39;49m\n";
  42. }
  43. #else
  44. (void)s;
  45. #endif
  46. }
  47. }
  48. #endif