File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ class LoggingErrorHandler : public kj::TaskSet::ErrorHandler
9898 EventLoop& m_loop;
9999};
100100
101+ // ! Log flags. Update stringify function if changed!
101102enum class Log {
102103 Trace = 0 ,
103104 Debug,
@@ -107,6 +108,8 @@ enum class Log {
107108 Raise,
108109};
109110
111+ kj::StringPtr KJ_STRINGIFY (Log flags);
112+
110113struct LogMessage {
111114
112115 // ! Message to be logged
Original file line number Diff line number Diff line change 2424#include < kj/debug.h>
2525#include < kj/function.h>
2626#include < kj/memory.h>
27+ #include < kj/string.h>
2728#include < map>
2829#include < memory>
2930#include < optional>
@@ -430,4 +431,16 @@ std::string LongThreadName(const char* exe_name)
430431 return g_thread_context.thread_name .empty () ? ThreadName (exe_name) : g_thread_context.thread_name ;
431432}
432433
434+ kj::StringPtr KJ_STRINGIFY (Log v)
435+ {
436+ switch (v) {
437+ case Log::Trace: return " Trace" ;
438+ case Log::Debug: return " Debug" ;
439+ case Log::Info: return " Info" ;
440+ case Log::Warning: return " Warning" ;
441+ case Log::Error: return " Error" ;
442+ case Log::Raise: return " Raise" ;
443+ }
444+ return " <Log?>" ;
445+ }
433446} // namespace mp
Original file line number Diff line number Diff line change 1313#include < exception>
1414#include < functional>
1515#include < future>
16- #include < iostream>
1716#include < kj/async.h>
1817#include < kj/async-io.h>
1918#include < kj/common.h>
@@ -67,9 +66,10 @@ class TestSetup
6766
6867 TestSetup (bool client_owns_connection = true )
6968 : thread{[&] {
70- EventLoop loop (" mptest" , [](mp::LogMessage log_data) {
71- std::cout << " LOG" << (int )log_data.level << " : " << log_data.message << " \n " ;
72- if (log_data.level == mp::Log::Raise) throw std::runtime_error (log_data.message );
69+ EventLoop loop (" mptest" , [](mp::LogMessage log) {
70+ // Info logs are not printed by default, but will be shown with `mptest --verbose`
71+ KJ_LOG (INFO, log.level , log.message );
72+ if (log.level == mp::Log::Raise) throw std::runtime_error (log.message );
7373 });
7474 auto pipe = loop.m_io_context .provider ->newTwoWayPipe ();
7575
You can’t perform that action at this time.
0 commit comments