Skip to content

Commit

Permalink
Remove flushes and fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Aug 28, 2024
1 parent f3d168c commit 9fbbb25
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
5 changes: 2 additions & 3 deletions include/gz/common/Console.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ namespace gz
/// initialized or false otherwise.
public: LogMessage(const char *_file,
int _line,
spdlog::level::level_enum _logLevel,
bool _fileInitialize = false);
spdlog::level::level_enum _logLevel);

/// \brief Destructor.
public: ~LogMessage();
Expand Down Expand Up @@ -80,7 +79,7 @@ namespace gz

/// \brief Output a message to a log file.
#define gzlog gz::common::LogMessage( \
__FILE__, __LINE__, spdlog::level::err, true).stream()
__FILE__, __LINE__, spdlog::level::err).stream()

/// \brief Output a message.
#define gzmsg gz::common::LogMessage( \
Expand Down
6 changes: 2 additions & 4 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ using namespace common;

/////////////////////////////////////////////////
LogMessage::LogMessage(const char *_file, int _line,
spdlog::level::level_enum _logLevel, bool _fileInitialize)
spdlog::level::level_enum _logLevel)
: severity(_logLevel),
sourceLocation(_file, _line, "")
{
// Use default initialization if needed.
if (_fileInitialize && !Console::initialized)
if (!Console::initialized)
Console::Init(".gz", "auto_default.log");
}

Expand Down Expand Up @@ -108,8 +108,6 @@ bool Console::Init(const std::string &_directory, const std::string &_filename)
logPath = joinPaths(logPath, _filename);

Console::Root().SetLogDestination(logPath.c_str());
Console::Root().RawLogger().log(spdlog::level::info,
"Setting log file output destination to {}", logPath.c_str());
Console::initialized = true;

return true;
Expand Down
20 changes: 0 additions & 20 deletions src/Console_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ TEST_F(Console_TEST, ColorWarnSlashN)
gzwarn << logString << " _n__ " << i << '\n';
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -235,8 +233,6 @@ TEST_F(Console_TEST, ColorWarnStdEndl)
gzwarn << logString << " endl " << i << std::endl;
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -267,8 +263,6 @@ TEST_F(Console_TEST, ColorDbgSlashN)
gzdbg << logString << " _n__ " << i << '\n';
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -299,8 +293,6 @@ TEST_F(Console_TEST, ColorDbgStdEndl)
gzdbg << logString << " endl " << i << std::endl;
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -331,8 +323,6 @@ TEST_F(Console_TEST, ColorMsgSlashN)
gzmsg << logString << " _n__ " << i << '\n';
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -363,8 +353,6 @@ TEST_F(Console_TEST, ColorMsgStdEndl)
gzmsg << logString << " endl " << i << std::endl;
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -395,8 +383,6 @@ TEST_F(Console_TEST, ColorErrSlashN)
gzerr << logString << " _n__ " << i << '\n';
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -427,8 +413,6 @@ TEST_F(Console_TEST, ColorErrStdEndl)
gzerr << logString << " endl " << i << std::endl;
}

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

for (int i = 0; i < g_messageRepeat; ++i)
Expand Down Expand Up @@ -456,8 +440,6 @@ TEST_F(Console_TEST, ColorMsg)

gzmsg << logString << std::endl;

common::Console::Root().RawLogger().flush();

std::string logContent = GetLogContent(logPath);

EXPECT_TRUE(logContent.find(logString) != std::string::npos);
Expand Down Expand Up @@ -527,8 +509,6 @@ TEST_F(Console_TEST, Prefix)
gzmsg << "message" << std::endl;
gzdbg << "debug" << std::endl;

common::Console::Root().RawLogger().flush();

// Get the logged content
std::string logContent = GetLogContent(logPath);

Expand Down

0 comments on commit 9fbbb25

Please sign in to comment.