Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flushes and fix tests #627

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Loading