diff --git a/src/l4/pkg/pong/example/main.cc b/src/l4/pkg/pong/example/main.cc index c562a809..5404161b 100644 --- a/src/l4/pkg/pong/example/main.cc +++ b/src/l4/pkg/pong/example/main.cc @@ -174,6 +174,8 @@ main() { redirect_to_log(std::cout); redirect_to_log(std::cerr); + redirect_to_log(L4::cout); + redirect_to_log(L4::cerr); Main().run(); return 0; }; diff --git a/src/l4/pkg/pong/include/logging.h b/src/l4/pkg/pong/include/logging.h index 0cc5f53d..49e6eaa7 100644 --- a/src/l4/pkg/pong/include/logging.h +++ b/src/l4/pkg/pong/include/logging.h @@ -2,10 +2,16 @@ #pragma once +#include + #include -void send_ipc(std::string const &msg); -void redirect_to_log(std::ostream &os); +static inline void +send_ipc(std::string const &msg); +static inline void +redirect_to_log(std::ostream &os); +static inline void +redirect_to_log(L4::BasicOStream &os); void send_ipc(std::string const &msg) @@ -29,16 +35,14 @@ public: Base::setp(&buffer.front(), &buffer.back()); } - int_type - overflow(int_type ch) override + int_type overflow(int_type ch) override { Log_Buffer::sync(); Base::sputc(ch); return ch; } - int - sync() override + int sync() override { send_ipc(buffer); Base::setp(this->pbase(), this->epptr()); @@ -46,6 +50,11 @@ public: } }; +class Log_Backend : public L4::IOBackend +{ + void write(char const *str, unsigned len) override { send_ipc({str, len}); }; +}; + void redirect_to_log(std::ostream &os) { @@ -55,3 +64,9 @@ redirect_to_log(std::ostream &os) // We should not free the old buffer because it has not been allocated // dynamically. } + +void +redirect_to_log(L4::BasicOStream &os) +{ + os = {new Log_Backend{}}; +} diff --git a/src/l4/pkg/pong/server/src/main.cc b/src/l4/pkg/pong/server/src/main.cc index 507924ef..f7d43677 100644 --- a/src/l4/pkg/pong/server/src/main.cc +++ b/src/l4/pkg/pong/server/src/main.cc @@ -43,6 +43,8 @@ main() { redirect_to_log(std::cout); redirect_to_log(std::cerr); + redirect_to_log(L4::cout); + redirect_to_log(L4::cerr); L4::cout << "PS Hello here am I\n";