• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 16618487122

30 Jul 2025 09:15AM UTC coverage: 44.743% (-1.6%) from 46.31%
16618487122

Pull #2626

github

web-flow
Merge 7efb2d277 into c0a7c02a0
Pull Request #2626: core: flush after each Log* line

235 of 348 new or added lines in 38 files covered. (67.53%)

415 existing lines in 21 files now uncovered.

15498 of 34638 relevant lines covered (44.74%)

313.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/mavsdk/core/log.cpp
1
#include "log.h"
2
#include "unused.h"
3

4
#include <mutex>
5

6
#if defined(WINDOWS)
7
#include <windows.h>
8
#define WIN_COLOR_RED 4
9
#define WIN_COLOR_GREEN 10
10
#define WIN_COLOR_YELLOW 14
11
#define WIN_COLOR_BLUE 1
12
#define WIN_COLOR_GRAY 8
13
#define WIN_COLOR_RESET 7
14
#else
15
#define ANSI_COLOR_RED "\x1b[31m"
16
#define ANSI_COLOR_GREEN "\x1b[32m"
17
#define ANSI_COLOR_YELLOW "\x1b[33m"
18
#define ANSI_COLOR_BLUE "\x1b[34m"
19
#define ANSI_COLOR_GRAY "\x1b[37m"
20
#define ANSI_COLOR_RESET "\x1b[0m"
21
#endif
22

23
namespace mavsdk {
24

25
static std::mutex callback_mutex_{};
26
static log::Callback callback_{nullptr};
27

28
// Dedicated mutex for logging operations - moved from header to avoid inlining issues
29
static std::mutex log_mutex_{};
30

31
std::mutex& get_log_mutex()
8,887✔
32
{
33
    return log_mutex_;
8,887✔
34
}
35

UNCOV
36
std::ostream& operator<<(std::ostream& os, std::byte b)
×
37
{
38
    return os << std::bitset<8>(std::to_integer<int>(b));
×
39
}
40

41
log::Callback& log::get_callback()
8,887✔
42
{
43
    std::lock_guard<std::mutex> lock(callback_mutex_);
8,887✔
44
    return callback_;
17,774✔
45
}
8,887✔
46

47
void log::subscribe(const log::Callback& callback)
×
48
{
49
    std::lock_guard<std::mutex> lock(callback_mutex_);
×
50
    callback_ = callback;
×
51
}
×
52

53
void set_color(Color color)
17,774✔
54
{
55
#if defined(WINDOWS)
56
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
57
    switch (color) {
58
        case Color::Red:
59
            SetConsoleTextAttribute(handle, WIN_COLOR_RED);
60
            break;
61
        case Color::Green:
62
            SetConsoleTextAttribute(handle, WIN_COLOR_GREEN);
63
            break;
64
        case Color::Yellow:
65
            SetConsoleTextAttribute(handle, WIN_COLOR_YELLOW);
66
            break;
67
        case Color::Blue:
68
            SetConsoleTextAttribute(handle, WIN_COLOR_BLUE);
69
            break;
70
        case Color::Gray:
71
            SetConsoleTextAttribute(handle, WIN_COLOR_GRAY);
72
            break;
73
        case Color::Reset:
74
            SetConsoleTextAttribute(handle, WIN_COLOR_RESET);
75
            break;
76
    }
77
#elif defined(ANDROID) || defined(IOS)
78
    UNUSED(color);
79
#else
80
    switch (color) {
17,774✔
81
        case Color::Red:
53✔
82
            std::cout << ANSI_COLOR_RED;
53✔
83
            break;
53✔
84
        case Color::Green:
7,538✔
85
            std::cout << ANSI_COLOR_GREEN;
7,538✔
86
            break;
7,538✔
87
        case Color::Yellow:
1,067✔
88
            std::cout << ANSI_COLOR_YELLOW;
1,067✔
89
            break;
1,067✔
90
        case Color::Blue:
229✔
91
            std::cout << ANSI_COLOR_BLUE;
229✔
92
            break;
229✔
93
        case Color::Gray:
×
94
            std::cout << ANSI_COLOR_GRAY;
×
95
            break;
×
96
        case Color::Reset:
8,887✔
97
            std::cout << ANSI_COLOR_RESET;
8,887✔
98
            break;
8,887✔
99
    }
100
#endif
101
}
17,774✔
102

103
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc