GCC Code Coverage Report


Directory: ./
File: src/iguana/services/Logger.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 27 30 90.0%
Functions: 7 7 100.0%
Branches: 12 30 40.0%

Line Branch Exec Source
1 #include "Logger.h"
2
3 namespace iguana {
4
5 203 Logger::Logger(std::string_view name, Level const lev, bool const enable_style)
6
1/2
✓ Branch 0 (3→4) taken 203 times.
✗ Branch 1 (3→23) not taken.
203 : m_name(name)
7
1/2
✓ Branch 0 (3→4) taken 203 times.
✗ Branch 1 (3→23) not taken.
203 , m_enable_style(enable_style)
8 {
9
2/4
✓ Branch 0 (14→15) taken 1421 times.
✓ Branch 1 (14→17) taken 203 times.
✗ Branch 2 (19→20) not taken.
✗ Branch 3 (19→22) not taken.
1624 m_level_names = {
10 {trace, "trace"},
11 {debug, "debug"},
12 {info, "info"},
13 {quiet, "quiet"},
14 {warn, "warn"},
15 {error, "error"},
16 1624 {silent, "silent"}};
17
1/2
✓ Branch 0 (17→18) taken 203 times.
✗ Branch 1 (17→28) not taken.
203 SetLevel(lev);
18
0/2
✗ Branch 0 (24→25) not taken.
✗ Branch 1 (24→27) not taken.
203 }
19
20 45 void Logger::SetLevel(std::string_view lev)
21 {
22
2/2
✓ Branch 0 (8→3) taken 246 times.
✓ Branch 1 (8→9) taken 1 times.
247 for(auto& [lev_i, lev_n] : m_level_names) {
23 202 if(lev == lev_n) {
24 44 m_level = lev_i;
25 44 Debug("log level set to '{}'", lev);
26 return;
27 }
28 }
29
1/2
✓ Branch 0 (11→12) taken 1 times.
✗ Branch 1 (11→15) not taken.
2 Error("Log level '{}' is not a known log level; the log level will remain at '{}'", lev, m_level_names.at(m_level));
30 }
31
32
1/2
✓ Branch 0 (2→3) taken 248 times.
✗ Branch 1 (2→16) not taken.
248 void Logger::SetLevel(Level const lev)
33 {
34 try {
35 auto level_name = m_level_names.at(lev);
36
1/2
✓ Branch 0 (5→6) taken 248 times.
✗ Branch 1 (5→14) not taken.
248 m_level = lev;
37
1/2
✓ Branch 0 (7→8) taken 248 times.
✗ Branch 1 (7→12) not taken.
248 Debug("log level set to '{}'", level_name);
38 }
39 catch(std::out_of_range const& ex) {
40 Error("Log level '{}' is not a known log level; the log level will remain at '{}'", static_cast<int>(lev), m_level_names.at(m_level));
41 }
42 248 }
43
44 59261 Logger::Level Logger::GetLevel()
45 {
46 59261 return m_level;
47 }
48
49 1 void Logger::EnableStyle()
50 {
51 1 m_enable_style = true;
52 1 }
53
54 1 void Logger::DisableStyle()
55 {
56 1 m_enable_style = false;
57 1 }
58
59 58974 std::string Logger::Header(std::string_view message, int const width)
60 {
61
1/2
✓ Branch 0 (3→4) taken 58974 times.
✗ Branch 1 (3→6) not taken.
58974 return fmt::format("{:=^{}}", fmt::format(" {} ", message), width);
62 }
63
64 }
65