Skip to content

Commit

Permalink
Remove flushes and fix tests (#627)
Browse files Browse the repository at this point in the history
* Remove flushes and fix tests

Signed-off-by: Addisu Z. Taddese <[email protected]>

* Remove doxygen parameter

Signed-off-by: Carlos Agüero <[email protected]>

---------

Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
  • Loading branch information
azeey and caguero committed Aug 28, 2024
1 parent ab269e8 commit 12a8d61
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
7 changes: 2 additions & 5 deletions include/gz/common/Console.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ namespace gz
/// \param[in] _file Filename.
/// \param[in] _line Line number.
/// \param[in] _logLevel Log level.
/// \param[in] _fileInitialize True if the file logger needs to be
/// 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 +77,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 @@ -209,8 +209,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 @@ -241,8 +239,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 @@ -273,8 +269,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 @@ -305,8 +299,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 @@ -337,8 +329,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 @@ -369,8 +359,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 @@ -401,8 +389,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 @@ -433,8 +419,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 @@ -462,8 +446,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 @@ -533,8 +515,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 12a8d61

Please sign in to comment.