From f3d168cfdc7eb4a8575edc4dfbf24cd8a98a5c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Wed, 28 Aug 2024 21:55:01 +0200 Subject: [PATCH] Restore defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- src/Console.cc | 13 ++++--------- src/Console_TEST.cc | 4 +++- test/integration/console.cc | 2 +- testing/src/AutoLogFixture_TEST.cc | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Console.cc b/src/Console.cc index 28a690c34..3b47c5258 100644 --- a/src/Console.cc +++ b/src/Console.cc @@ -20,6 +20,7 @@ #include #endif +#include #include #include #include @@ -42,11 +43,7 @@ LogMessage::LogMessage(const char *_file, int _line, { // Use default initialization if needed. if (_fileInitialize && !Console::initialized) - { Console::Init(".gz", "auto_default.log"); - // Allow gzlog to pass through. - Console::SetVerbosity(5); - } } ///////////////////////////////////////////////// @@ -137,7 +134,7 @@ void Console::SetVerbosity(const int _level) { if (_level < 0) { - Console::Root().RawLogger().log(spdlog::level::info, + Console::Root().RawLogger().log(spdlog::level::err, "Negative verbosity level. Ignoring it"); return; } @@ -163,12 +160,10 @@ void Console::SetVerbosity(const int _level) gz::common::Console::Root().SetConsoleSinkLevel(spdlog::level::trace); break; default: - Console::Root().RawLogger().log(spdlog::level::info, - "Unknown verbosity level. Values should be between 0 and 5. Ignoring it"); - return; + gz::common::Console::Root().SetConsoleSinkLevel(spdlog::level::trace); } - verbosity = _level; + verbosity = std::min(5, _level); } ////////////////////////////////////////////////// diff --git a/src/Console_TEST.cc b/src/Console_TEST.cc index e1279a65a..922c9f5ee 100644 --- a/src/Console_TEST.cc +++ b/src/Console_TEST.cc @@ -489,6 +489,8 @@ TEST_F(Console_TEST, ColorErr) /// \brief Test Console::Verbosity TEST_F(Console_TEST, Verbosity) { + EXPECT_EQ(1, common::Console::Verbosity()); + common::Console::SetVerbosity(2); EXPECT_EQ(2, common::Console::Verbosity()); @@ -496,7 +498,7 @@ TEST_F(Console_TEST, Verbosity) EXPECT_EQ(2, common::Console::Verbosity()); common::Console::SetVerbosity(1000); - EXPECT_EQ(2, common::Console::Verbosity()); + EXPECT_EQ(5, common::Console::Verbosity()); } ///////////////////////////////////////////////// diff --git a/test/integration/console.cc b/test/integration/console.cc index 18a080c6d..fb1f0d500 100644 --- a/test/integration/console.cc +++ b/test/integration/console.cc @@ -37,7 +37,7 @@ TEST(Console_TEST, LogInitAfterConsoleOut) gz::common::Console::SetVerbosity(4); // Before console is initialized, logs go to default file location - gzlog << "Error before logging initialized" << std::endl; + gzerr << "Error before logging initialized" << std::endl; { auto defaultPath = gz::common::joinPaths(home, diff --git a/testing/src/AutoLogFixture_TEST.cc b/testing/src/AutoLogFixture_TEST.cc index 207bc5783..aa598711f 100644 --- a/testing/src/AutoLogFixture_TEST.cc +++ b/testing/src/AutoLogFixture_TEST.cc @@ -28,7 +28,7 @@ TEST_F(AutoLogFixture, AutoLogFixture) EXPECT_FALSE(this->FullLogPath().empty()); EXPECT_TRUE(this->LogContent().empty()); - Console::SetVerbosity(4); + Console::SetVerbosity(0); gzdbg << "This is a debug" << std::endl; gz::common::Console::Root().RawLogger().flush(); EXPECT_FALSE(this->LogContent().empty());