SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
logger.cpp
Go to the documentation of this file.
1
#include "
tests.hpp
"
2
3
#include <mutex>
4
#include <vector>
5
6
#include <
logging/logger.hpp
>
7
8
using namespace
SILICON::core
;
9
using namespace
SILICON::logging
;
10
11
TEST
(LoggerTests, InitializeAndShutdownAreSafe)
12
{
13
EXPECT_NO_THROW(
Logger::initialize
());
14
EXPECT_NO_THROW(
Logger::shutdown
());
15
EXPECT_NO_THROW(
Logger::initialize
());
16
EXPECT_NO_THROW(
Logger::shutdown
());
17
}
18
19
TEST
(LoggerTests, CallbackSinkReceivesCategorySeverityAndMessage)
20
{
21
Logger::initialize
();
22
Logger::setMinimumLevel
(
LogLevel::Trace
);
23
24
std::mutex mutex;
25
std::vector<LogMessage> messages;
26
const
auto
handle =
Logger::addCallbackSink
([&](
const
LogMessage
& message) {
27
const
std::lock_guard lock(mutex);
28
messages.push_back(message);
29
});
30
31
Logger
log(
"simulation"
);
32
EXPECT_NO_THROW(log.warning(
"Circuit contains a combinational loop"
));
33
34
Logger::removeSink
(handle);
35
36
ASSERT_EQ(messages.size(), 1u);
37
EXPECT_EQ(messages.front().level,
LogLevel::Warning
);
38
EXPECT_EQ(messages.front().category,
"simulation"
);
39
EXPECT_EQ(messages.front().message,
"Circuit contains a combinational loop"
);
40
EXPECT_NE(messages.front().formatted.find(
"simulation"
), std::string::npos);
41
EXPECT_NE(messages.front().formatted.find(
"combinational loop"
), std::string::npos);
42
43
Logger::shutdown
();
44
}
SILICON::logging::Logger
Definition
logger.hpp:26
SILICON::logging::Logger::initialize
static void initialize()
Definition
logger.cpp:180
SILICON::logging::Logger::addCallbackSink
static SinkHandle addCallbackSink(CallbackSink callback)
Definition
logger.cpp:240
SILICON::logging::Logger::setMinimumLevel
static void setMinimumLevel(LogLevel level)
Definition
logger.cpp:231
SILICON::logging::Logger::removeSink
static void removeSink(SinkHandle handle)
Definition
logger.cpp:258
SILICON::logging::Logger::shutdown
static void shutdown()
Definition
logger.cpp:187
logger.hpp
SILICON::core
Definition
activeKeyGuard.hpp:28
SILICON::logging
Definition
logger.cpp:27
SILICON::logging::LogLevel::Warning
@ Warning
Definition
logger.hpp:14
SILICON::logging::LogLevel::Trace
@ Trace
Definition
logger.hpp:11
SILICON::logging::LogMessage
Definition
logger.hpp:19
TEST
TEST(LoggerTests, InitializeAndShutdownAreSafe)
Definition
logger.cpp:11
tests.hpp
tests
logger.cpp
Generated by
1.17.0