Skip to content

Commit 72ed9d9

Browse files
committed
Logging: API Breaking change: Pass log level to logging callback
Users will need to update their logging callbacks accordingly.
1 parent fa4e443 commit 72ed9d9

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

example/calculator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class InitImpl : public Init
3737
}
3838
};
3939

40-
static void LogPrint(bool raise, const std::string& message)
40+
static void LogPrint(mp::LogLevel log_level, const std::string& message)
4141
{
42-
if (raise) throw std::runtime_error(message);
42+
if (log_level == mp::LogLevel::Exception) throw std::runtime_error(message);
4343
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
4444
}
4545

example/example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ static auto Spawn(mp::EventLoop& loop, const std::string& process_argv0, const s
3535
return std::make_tuple(mp::ConnectStream<InitInterface>(loop, fd), pid);
3636
}
3737

38-
static void LogPrint(bool raise, const std::string& message)
38+
static void LogPrint(mp::LogLevel log_level, const std::string& message)
3939
{
40-
if (raise) throw std::runtime_error(message);
40+
if (log_level == mp::LogLevel::Exception) throw std::runtime_error(message);
4141
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
4242
}
4343

example/printer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class InitImpl : public Init
3232
std::unique_ptr<Printer> makePrinter() override { return std::make_unique<PrinterImpl>(); }
3333
};
3434

35-
static void LogPrint(bool raise, const std::string& message)
35+
static void LogPrint(mp::LogLevel log_level, const std::string& message)
3636
{
37-
if (raise) throw std::runtime_error(message);
37+
if (log_level == mp::LogLevel::Exception) throw std::runtime_error(message);
3838
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
3939
}
4040

include/mp/proxy-io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ enum class LogLevel {
107107
Exception,
108108
};
109109

110-
using LogFn = std::function<void(bool raise, std::string message)>;
110+
using LogFn = std::function<void(LogLevel level, std::string message)>;
111111

112112
class Logger
113113
{
@@ -134,7 +134,7 @@ class Logger
134134

135135
~Logger() noexcept(false)
136136
{
137-
if (enabled()) m_fn(m_log_level == LogLevel::Exception, m_buffer.str());
137+
if (enabled()) m_fn(m_log_level, m_buffer.str());
138138
}
139139

140140
template <typename T>

test/mp/test/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class TestSetup
6060

6161
TestSetup(bool client_owns_connection = true)
6262
: thread{[&] {
63-
EventLoop loop("mptest", [](bool raise, const std::string& log) {
64-
std::cout << "LOG" << raise << ": " << log << "\n";
65-
if (raise) throw std::runtime_error(log);
63+
EventLoop loop("mptest", [](mp::LogLevel log_level, const std::string& log) {
64+
std::cout << "LOG" << (int)log_level << ": " << log << "\n";
65+
if (log_level == mp::LogLevel::Exception) throw std::runtime_error(log);
6666
});
6767
auto pipe = loop.m_io_context.provider->newTwoWayPipe();
6868

0 commit comments

Comments
 (0)