log.cpp 786 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "log.h"
  6. #include "console_server.h"
  7. #include "string_utils.h"
  8. #include "os.h"
  9. #if CROWN_DEBUG
  10. namespace crown
  11. {
  12. namespace log_internal
  13. {
  14. void logx(LogSeverity::Enum sev, const char* msg, va_list args)
  15. {
  16. char buf[2048];
  17. int len = vsnprintf(buf, sizeof(buf), msg, args);
  18. if (len > (int)sizeof(buf))
  19. len = sizeof(buf) - 1;
  20. buf[len] = '\0';
  21. console_server_globals::console().log(buf, sev);
  22. os::log(buf);
  23. }
  24. void logx(LogSeverity::Enum sev, const char* msg, ...)
  25. {
  26. va_list args;
  27. va_start(args, msg);
  28. logx(sev, msg, args);
  29. va_end(args);
  30. }
  31. } // namespace log
  32. } // namespace crown
  33. #endif // CROWN_DEBUG