summaryrefslogtreecommitdiff
path: root/test/buildtool/logging
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-13 14:54:09 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-19 10:31:33 +0100
commit70bf05ffeb9ef01a72a150abc3e3a4b89f451117 (patch)
tree38b794d90075d687e35ece05707e13becc010c7b /test/buildtool/logging
parent435e473e75f5892b69cf4ad904c3ccf19f8f79dd (diff)
downloadjustbuild-70bf05ffeb9ef01a72a150abc3e3a4b89f451117.tar.gz
logger: Add common methods for global and named loggers
This allows to be explicit and thus have better control on where messages get logged.
Diffstat (limited to 'test/buildtool/logging')
-rw-r--r--test/buildtool/logging/logger.test.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/buildtool/logging/logger.test.cpp b/test/buildtool/logging/logger.test.cpp
index 7a265323..eac80424 100644
--- a/test/buildtool/logging/logger.test.cpp
+++ b/test/buildtool/logging/logger.test.cpp
@@ -342,3 +342,75 @@ TEST_CASE_METHOD(TwoGlobalSinksFixture,
}
}
}
+
+TEST_CASE_METHOD(OneGlobalSinkFixture,
+ "Common interface for global and local named loggers"
+ "[logger]") {
+ // global logs will be forwarded to instance: 0
+ int global_instance = 0;
+
+ // create local logger with separate sink instance
+ Logger logger("OwnSinkLogger", {LogSinkTest::CreateFactory()});
+ // local logs should be forwarded to new sink instance: 1
+ int local_instance = 1;
+
+ SECTION("global instance") {
+ // create log outside of log limit
+ Logger::Log(nullptr, LogLevel::Trace, "first");
+ CHECK(TestPrints::Read(global_instance).empty());
+
+ SECTION("create log within log limit") {
+ Logger::Log(nullptr, LogLevel::Info, "second");
+ auto prints = TestPrints::Read(global_instance);
+ REQUIRE(prints.size() == 1);
+ CHECK(prints[0] == "INFO: second");
+
+ SECTION("increase log limit create log within log limit") {
+ LogConfig::SetLogLimit(LogLevel::Trace);
+ Logger::Log(nullptr, LogLevel::Trace, "third");
+ auto prints = TestPrints::Read(global_instance);
+ REQUIRE(prints.size() == 2);
+ CHECK(prints[1] == "TRACE: third");
+
+ SECTION("log via lambda function") {
+ Logger::Log(nullptr, LogLevel::Trace, [] {
+ return std::string{"forth"};
+ });
+ auto prints = TestPrints::Read(global_instance);
+ REQUIRE(prints.size() == 3);
+ CHECK(prints[2] == "TRACE: forth");
+ }
+ }
+ }
+ }
+
+ SECTION("named instance") {
+ // create log outside of log limit
+ Logger::Log(&logger, LogLevel::Trace, "first");
+ CHECK(TestPrints::Read(local_instance).empty());
+
+ SECTION("create log within log limit") {
+ Logger::Log(&logger, LogLevel::Info, "second");
+ auto prints = TestPrints::Read(local_instance);
+ REQUIRE(prints.size() == 1);
+ CHECK(prints[0] == "INFO (OwnSinkLogger): second");
+
+ SECTION("increase log limit create log within log limit") {
+ logger.SetLogLimit(LogLevel::Trace);
+ Logger::Log(&logger, LogLevel::Trace, "third");
+ auto prints = TestPrints::Read(local_instance);
+ REQUIRE(prints.size() == 2);
+ CHECK(prints[1] == "TRACE (OwnSinkLogger): third");
+
+ SECTION("log via lambda function") {
+ Logger::Log(&logger, LogLevel::Trace, [] {
+ return std::string{"forth"};
+ });
+ auto prints = TestPrints::Read(local_instance);
+ REQUIRE(prints.size() == 3);
+ CHECK(prints[2] == "TRACE (OwnSinkLogger): forth");
+ }
+ }
+ }
+ }
+}