Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "Logger.h" | ||
2 | |||
3 | namespace iguana { | ||
4 | |||
5 | 188 | Logger::Logger(std::string_view name, Level const lev, bool const enable_style) | |
6 |
1/2✓ Branch 0 taken 188 times.
✗ Branch 1 not taken.
|
188 | : m_name(name) |
7 |
1/2✓ Branch 0 taken 188 times.
✗ Branch 1 not taken.
|
188 | , m_enable_style(enable_style) |
8 | { | ||
9 |
2/4✓ Branch 0 taken 1316 times.
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1504 | m_level_names = { |
10 | {trace, "trace"}, | ||
11 | {debug, "debug"}, | ||
12 | {info, "info"}, | ||
13 | {quiet, "quiet"}, | ||
14 | {warn, "warn"}, | ||
15 | {error, "error"}, | ||
16 | 1504 | {silent, "silent"}}; | |
17 |
1/2✓ Branch 0 taken 188 times.
✗ Branch 1 not taken.
|
188 | SetLevel(lev); |
18 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
188 | } |
19 | |||
20 | 43 | void Logger::SetLevel(std::string_view lev) | |
21 | { | ||
22 |
2/2✓ Branch 0 taken 236 times.
✓ Branch 1 taken 1 times.
|
237 | for(auto& [lev_i, lev_n] : m_level_names) { |
23 | 194 | if(lev == lev_n) { | |
24 | 42 | m_level = lev_i; | |
25 | 42 | Debug("log level set to '{}'", lev); | |
26 | return; | ||
27 | } | ||
28 | } | ||
29 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 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 taken 230 times.
✗ Branch 1 not taken.
|
230 | void Logger::SetLevel(Level const lev) |
33 | { | ||
34 | try { | ||
35 | auto level_name = m_level_names.at(lev); | ||
36 |
1/2✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
|
230 | m_level = lev; |
37 |
1/2✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
|
230 | 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 | 230 | } | |
43 | |||
44 | 51256 | Logger::Level Logger::GetLevel() | |
45 | { | ||
46 | 51256 | 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 | 50974 | std::string Logger::Header(std::string_view message, int const width) | |
60 | { | ||
61 |
1/2✓ Branch 0 taken 50974 times.
✗ Branch 1 not taken.
|
50974 | return fmt::format("{:=^{}}", fmt::format(" {} ", message), width); |
62 | } | ||
63 | |||
64 | } | ||
65 |