Chrysalis - Logging Test Coverage


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

Line Branch Decision Call Exec Source
1 #include "formatters/ColoredLevelFlagFormatter.h"
2
3 #include <ctime>
4 #include <array>
5 #include <memory>
6 #include <cstring>
7
8 #include <spdlog/common.h>
9 #include <spdlog/details/log_msg.h>
10 #include <spdlog/pattern_formatter.h>
11
12 #include "formatters/LevelFlagFormatter.h"
13
14 using namespace Logging;
15
16 27 void ColoredLevelFlagFormatter::format(const spdlog::details::log_msg& msg, const std::tm& tm_time, spdlog::memory_buf_t& dest) {
17 static constexpr std::array<const char*, 7> LEVEL_COLORS = {
18 "\033[90m", // trace
19 "\033[36m", // debug
20 "\033[32m", // info
21 "\033[33m", // warn
22 "\033[31m", // err
23 "\033[1;35m", // critical
24 "\033[0m", // off
25 };
26 static constexpr auto RESET_COLOR = "\033[0m";
27
28
4/4
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
27 const char* levelColor = LEVEL_COLORS[msg.level];
29
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(levelColor, levelColor + std::strlen(levelColor));
30
5/5
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
27 LevelFlagFormatter::format(msg, tm_time, dest);
31
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));
32 27 }
33
34 3 std::unique_ptr<spdlog::custom_flag_formatter> ColoredLevelFlagFormatter::clone() const {
35
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 ColoredLevelFlagFormatter(*this));
36 }
37