Coverage Report

Created: 2026-04-12 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yoga/yoga/debug/Log.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
#include <yoga/debug/Log.h>
9
10
#ifdef ANDROID
11
#include <android/log.h>
12
#endif
13
14
namespace facebook::yoga {
15
16
namespace {
17
18
void vlog(
19
    const yoga::Config* config,
20
    const yoga::Node* node,
21
    LogLevel level,
22
    const char* format,
23
0
    va_list args) {
24
0
  if (config == nullptr) {
25
0
    getDefaultLogger()(nullptr, node, unscopedEnum(level), format, args);
26
0
  } else {
27
0
    config->log(node, level, format, args);
28
0
  }
29
0
}
30
} // namespace
31
32
0
void log(LogLevel level, const char* format, ...) noexcept {
33
0
  va_list args;
34
0
  va_start(args, format);
35
0
  vlog(nullptr, nullptr, level, format, args);
36
0
  va_end(args);
37
0
}
38
39
void log(
40
    const yoga::Node* node,
41
    LogLevel level,
42
    const char* format,
43
0
    ...) noexcept {
44
0
  va_list args;
45
0
  va_start(args, format);
46
0
  vlog(
47
0
      node == nullptr ? nullptr : node->getConfig(), node, level, format, args);
48
0
  va_end(args);
49
0
}
50
51
void log(
52
    const yoga::Config* config,
53
    LogLevel level,
54
    const char* format,
55
0
    ...) noexcept {
56
0
  va_list args;
57
0
  va_start(args, format);
58
0
  vlog(config, nullptr, level, format, args);
59
0
  va_end(args);
60
0
}
61
62
1.03k
YGLogger getDefaultLogger() {
63
1.03k
  return [](const YGConfigConstRef /*config*/,
64
1.03k
            const YGNodeConstRef /*node*/,
65
1.03k
            YGLogLevel level,
66
1.03k
            const char* format,
67
1.03k
            va_list args) -> int {
68
#ifdef ANDROID
69
    int androidLevel = YGLogLevelDebug;
70
    switch (level) {
71
      case YGLogLevelFatal:
72
        androidLevel = ANDROID_LOG_FATAL;
73
        break;
74
      case YGLogLevelError:
75
        androidLevel = ANDROID_LOG_ERROR;
76
        break;
77
      case YGLogLevelWarn:
78
        androidLevel = ANDROID_LOG_WARN;
79
        break;
80
      case YGLogLevelInfo:
81
        androidLevel = ANDROID_LOG_INFO;
82
        break;
83
      case YGLogLevelDebug:
84
        androidLevel = ANDROID_LOG_DEBUG;
85
        break;
86
      case YGLogLevelVerbose:
87
        androidLevel = ANDROID_LOG_VERBOSE;
88
        break;
89
    }
90
    return __android_log_vprint(androidLevel, "yoga", format, args);
91
#else
92
0
    switch (level) {
93
0
      case YGLogLevelError:
94
0
      case YGLogLevelFatal:
95
0
        return vfprintf(stderr, format, args);
96
0
      case YGLogLevelWarn:
97
0
      case YGLogLevelInfo:
98
0
      case YGLogLevelDebug:
99
0
      case YGLogLevelVerbose:
100
0
      default:
101
0
        return vprintf(format, args);
102
0
    }
103
0
#endif
104
0
  };
105
1.03k
}
106
107
} // namespace facebook::yoga