log.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the LICENSE
  5. * file in the root directory of this source tree.
  6. */
  7. #include "log.h"
  8. #include "Yoga.h"
  9. #include "YGConfig.h"
  10. #include "YGNode.h"
  11. namespace facebook {
  12. namespace yoga {
  13. namespace detail {
  14. namespace {
  15. void vlog(
  16. YGConfig* config,
  17. YGNode* node,
  18. YGLogLevel level,
  19. void* context,
  20. const char* format,
  21. va_list args) {
  22. YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault();
  23. logConfig->log(logConfig, node, level, context, format, args);
  24. if (level == YGLogLevelFatal) {
  25. abort();
  26. }
  27. }
  28. } // namespace
  29. void Log::log(
  30. YGNode* node,
  31. YGLogLevel level,
  32. void* context,
  33. const char* format,
  34. ...) noexcept {
  35. va_list args;
  36. va_start(args, format);
  37. vlog(
  38. node == nullptr ? nullptr : node->getConfig(),
  39. node,
  40. level,
  41. context,
  42. format,
  43. args);
  44. va_end(args);
  45. }
  46. void Log::log(
  47. YGConfig* config,
  48. YGLogLevel level,
  49. void* context,
  50. const char* format,
  51. ...) noexcept {
  52. va_list args;
  53. va_start(args, format);
  54. vlog(config, nullptr, level, context, format, args);
  55. va_end(args);
  56. }
  57. } // namespace detail
  58. } // namespace yoga
  59. } // namespace facebook