Skip to content
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
4 changes: 2 additions & 2 deletions include/pressio-log/logger/logger_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ inline void Logger::log(LogLevel level, const std::string& message) {
if (current_rank_ == logging_rank_) {
switch (level) {
case LogLevel::none: return;
case LogLevel::sparse: sparse_(message); break;
case LogLevel::sparse: sparse_(message); break;
case LogLevel::info: info_(message); break;
case LogLevel::debug: debug_(message); break;
case LogLevel::warning: warning_(message); break;
Expand All @@ -136,7 +136,7 @@ inline void Logger::log(LogLevel level, const std::string& fmt_str, Args&&... ar
} catch(const fmt::v11::format_error&) {
std::ostringstream oss;
oss << "fmt could not format given string: " << fmt_str << " with args:\n";
((oss << " " << std::to_string(args) << "\n"), ...);
((oss << " " << args << "\n"), ...);
throw std::runtime_error(oss.str());
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ add_utest_serial(
${CMAKE_CURRENT_SOURCE_DIR}/test_logger_write_serial.cc
)

add_utest_serial(
test_logger_string
${CMAKE_CURRENT_SOURCE_DIR}/test_logger_string.cc
)

if (PRESSIO_ENABLE_TPL_MPI)
add_utest_mpi(
test_logger_mpi gTestMain_mpi 3
Expand Down
26 changes: 26 additions & 0 deletions tests/logging/test_logger_string.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <gtest/gtest.h>

#include "helpers.hpp"
#include "LoggerTest.hpp"
#include "pressio-log/core.hpp"

TEST_F(LoggerTest, Logger_String_Formatting) {
PRESSIOLOG_SET_LEVEL(pressiolog::LogLevel::debug);

CoutRedirector redirect;

PRESSIOLOG_SPARSE("{}", "hey there");
PRESSIOLOG_SPARSE("{} {}", "two", "strings");
PRESSIOLOG_SPARSE("{}", "Debug");
PRESSIOLOG_SPARSE("{}: {}", 2.1, "number");
PRESSIOLOG_SPARSE("{}", "Error");

std::string output = redirect.str();

EXPECT_TRUE(check_output(output, "hey there", true));
EXPECT_TRUE(check_output(output, "two strings", true));
EXPECT_TRUE(check_output(output, "Debug", true));
EXPECT_TRUE(check_output(output, "2.1: number", true));
EXPECT_TRUE(check_output(output, "Error", true));
EXPECT_TRUE(check_output(output, "could not format given string", false));
}