Skip to content

Commit

Permalink
Restore defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Aug 28, 2024
1 parent f0887d2 commit f3d168c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
13 changes: 4 additions & 9 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Windows.h>
#endif

#include <algorithm>
#include <filesystem>
#include <iostream>
#include <sstream>
Expand All @@ -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);
}
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

//////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion src/Console_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,16 @@ 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());

common::Console::SetVerbosity(-1);
EXPECT_EQ(2, common::Console::Verbosity());

common::Console::SetVerbosity(1000);
EXPECT_EQ(2, common::Console::Verbosity());
EXPECT_EQ(5, common::Console::Verbosity());
}

/////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion test/integration/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion testing/src/AutoLogFixture_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f3d168c

Please sign in to comment.