Chrysalis - Logging Test Coverage


logging/
File: logging/src/ColoredNameFlagFormatter.cpp
Date: 2026-08-27 18:35:06
Lines:
8/8
100.0%
Functions:
2/2
100.0%
Branches:
2/4
50.0%
Decisions:
0/0
-%
Calls:
31/31
100.0%

Line Branch Decision Call Exec Source
1 #include "formatters/ColoredNameFlagFormatter.h"
2
3 #include <ctime>
4 #include <array>
5 #include <memory>
6 #include <cstring>
7 #include <functional>
8 #include <string_view>
9
10 #include <spdlog/common.h>
11 #include <spdlog/details/log_msg.h>
12 #include <spdlog/pattern_formatter.h>
13
14 #include "formatters/NameFlagFormatter.h"
15
16 using namespace Logging;
17
18 27 void ColoredNameFlagFormatter::format(const spdlog::details::log_msg& msg, const std::tm& tm_time, spdlog::memory_buf_t& dest) {
19 static constexpr auto COLOR_PALETTE = std::to_array<const char*>({
20 "\033[34m", // blue
21 "\033[94m", // bright blue
22 "\033[96m", // bright cyan
23 "\033[92m", // bright green
24 "\033[95m", // bright magenta
25 "\033[93m", // bright yellow
26 "\033[91m", // bright red
27 "\033[97m", // bright white
28 });
29 static constexpr short COLOR_PALETTE_SIZE = std::size(COLOR_PALETTE);
30 static constexpr auto RESET_COLOR = "\033[0m";
31
32
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 27 times.
13/13
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
✓ Call 5 invoked.
✓ Call 8 invoked.
✓ Call 9 invoked.
✓ Call 10 invoked.
✓ Call 11 invoked.
✓ Call 12 invoked.
✓ Call 13 invoked.
✓ Call 14 invoked.
27 const char* color = COLOR_PALETTE[std::hash<std::string_view>{}(msg.logger_name.data()) % COLOR_PALETTE_SIZE];
33
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
4/4
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 4 invoked.
✓ Call 5 invoked.
27 dest.append(color, color + std::strlen(color));
34
5/5
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
27 NameFlagFormatter::format(msg, tm_time, dest);
35
4/4
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
27 dest.append(RESET_COLOR, RESET_COLOR + std::strlen(RESET_COLOR));
36 27 }
37
38 3 std::unique_ptr<spdlog::custom_flag_formatter> ColoredNameFlagFormatter::clone() const {
39
5/5
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
3 return std::unique_ptr<custom_flag_formatter>(new ColoredNameFlagFormatter(*this));
40 }
41