Chrysalis - Logging Test Coverage


logging/
File: logging/include/Logger.h
Date: 2026-08-27 18:35:06
Lines:
16/27
59.3%
Functions:
7/51
13.7%
Branches:
5/10
50.0%
Decisions:
0/0
-%
Calls:
47/78
60.3%

Line Branch Decision Call Exec Source
1 #ifndef CHRYSALIS_LOGGER_H
2 #define CHRYSALIS_LOGGER_H
3
4 #include <spdlog/spdlog.h>
5 #include <spdlog/sinks/basic_file_sink.h>
6
7 #include "LoggerFormatter.h"
8 #include "LoggingLibraryExport.h"
9 #include "formatters/NameFlagFormatter.h"
10 #include "formatters/LevelFlagFormatter.h"
11
12 namespace Logging {
13 class LOGGING Logger {
14 friend class LoggerRegistry;
15 explicit Logger(const std::string& loggingDirectory, const char* name);
16 public:
17 constexpr static short LOGGER_NAME_LENGTH = 20;
18
19 const char* getName() const;
20
21 spdlog::level::level_enum getLevel() const;
22 void setLevel(spdlog::level::level_enum level);
23
24 void flush() const;
25 void addSink(const std::shared_ptr<spdlog::sinks::sink>& sink);
26
27 template<typename... Args>
28 6368 void log(spdlog::level::level_enum lvl, spdlog::format_string_t<Args...> fmt, Args &&... args) {
29
8/10
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
✓ Call 5 invoked.
✓ Call 6 invoked.
✓ Call 7 invoked.
✗ Call 8 not invoked.
✗ Call 9 not invoked.
6368 logger_.log(lvl, fmt, std::forward<Args>(args)...);
30 6368 }
31
32 template<typename... Args>
33 3168 void trace(spdlog::format_string_t<Args...> fmt, Args &&... args) {
34
4/4
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
3168 log(spdlog::level::trace, fmt, std::forward<Args>(args)...);
35 3168 }
36
37 template<typename... Args>
38 1 void debug(spdlog::format_string_t<Args...> fmt, Args &&... args) {
39
4/6
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✗ Call 4 not invoked.
✗ Call 5 not invoked.
1 log(spdlog::level::debug, fmt, std::forward<Args>(args)...);
40 1 }
41
42 template<typename... Args>
43 31 void info(spdlog::format_string_t<Args...> fmt, Args &&... args) {
44
4/6
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✗ Call 4 not invoked.
✗ Call 5 not invoked.
31 log(spdlog::level::info, fmt, std::forward<Args>(args)...);
45 31 }
46
47 template<typename... Args>
48 ✗ void warn(spdlog::format_string_t<Args...> fmt, Args &&... args) {
49
0/4
✗ Call 0 not invoked.
✗ Call 1 not invoked.
✗ Call 2 not invoked.
✗ Call 3 not invoked.
✗ log(spdlog::level::warn, fmt, std::forward<Args>(args)...);
50 ✗ }
51
52 template<typename... Args>
53 ✗ void error(spdlog::format_string_t<Args...> fmt, Args &&... args) {
54
0/6
✗ Call 0 not invoked.
✗ Call 1 not invoked.
✗ Call 2 not invoked.
✗ Call 3 not invoked.
✗ Call 4 not invoked.
✗ Call 5 not invoked.
✗ log(spdlog::level::err, fmt, std::forward<Args>(args)...);
55 ✗ }
56
57 template<typename... Args>
58 ✗ void critical(spdlog::format_string_t<Args...> fmt, Args &&... args) {
59
0/4
✗ Call 0 not invoked.
✗ Call 1 not invoked.
✗ Call 2 not invoked.
✗ Call 3 not invoked.
✗ log(spdlog::level::critical, fmt, std::forward<Args>(args)...);
60
0/1
✗ Call 0 not invoked.
✗ spdlog::shutdown();
61 ✗ exit(1);
62 }
63
64 private:
65 template<typename Mutex>
66 8 static std::shared_ptr<spdlog::sinks::basic_file_sink<Mutex>> createFileSink(const std::string& loggingDirectory, const std::string& name) {
67
4/8
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
✓ Branch 20 taken 8 times.
✗ Branch 21 not taken.
21/28
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 4 invoked.
✓ Call 5 invoked.
✓ Call 6 invoked.
✓ Call 9 invoked.
✓ Call 10 invoked.
✓ Call 13 invoked.
✓ Call 14 invoked.
✓ Call 17 invoked.
✓ Call 18 invoked.
✓ Call 19 invoked.
✓ Call 22 invoked.
✓ Call 23 invoked.
✓ Call 24 invoked.
✓ Call 25 invoked.
✓ Call 26 invoked.
✓ Call 27 invoked.
✓ Call 28 invoked.
✗ Call 29 not invoked.
✗ Call 30 not invoked.
✗ Call 31 not invoked.
✗ Call 32 not invoked.
✗ Call 33 not invoked.
✗ Call 34 not invoked.
✗ Call 35 not invoked.
8 const auto sink = std::make_shared<spdlog::sinks::basic_file_sink<Mutex>>(loggingDirectory + "/" + name + ".log", true);
68
1/2
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
6/8
✓ Call 0 invoked.
✓ Call 1 invoked.
✓ Call 2 invoked.
✓ Call 3 invoked.
✓ Call 6 invoked.
✓ Call 7 invoked.
✗ Call 8 not invoked.
✗ Call 9 not invoked.
8 LoggerFormatter<NameFlagFormatter, LevelFlagFormatter>::apply(sink);
69 8 return sink;
70
0/1
✗ Call 0 not invoked.
✗ }
71
72 void setLoggingDirectory(const std::string& loggingDirectory);
73 void setCommonFileSink(const std::shared_ptr<spdlog::sinks::basic_file_sink_mt>& sink);
74
75 const char* name_;
76
77 spdlog::logger logger_;
78 std::shared_ptr<spdlog::sinks::basic_file_sink_mt> fileSink_;
79 };
80 }
81
82 #endif //CHRYSALIS_LOGGER_H
83