diff --git a/deps/ox/.gdblogger.json b/deps/ox/.gdblogger.json new file mode 100644 index 00000000..5ef494d8 --- /dev/null +++ b/deps/ox/.gdblogger.json @@ -0,0 +1,12 @@ +{ + "log_functions": [ + { + "function": "ox::trace::gdblogger::captureLogFunc", + "ignore_frames": 3, + "file_var": "file", + "line_var": "line", + "channel_var": "ch", + "msg_var": "msg" + } + ] +} diff --git a/deps/ox/src/ox/trace/trace.cpp b/deps/ox/src/ox/trace/trace.cpp index a590a446..d8df0998 100644 --- a/deps/ox/src/ox/trace/trace.cpp +++ b/deps/ox/src/ox/trace/trace.cpp @@ -9,6 +9,8 @@ #if defined(OX_USE_STDLIB) #include #include +#include +#include #endif #include @@ -17,7 +19,19 @@ namespace ox::trace { -static const auto OxPrintTrace = std::getenv("OXTRACE") != nullptr; +static const auto OxPrintTrace = std::getenv("OXTRACE"); + +namespace gdblogger { + +void captureLogFunc([[maybe_unused]] const char *file, [[maybe_unused]] int line, + [[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) { +} + +void logFunc(const char *file, int line, const char *ch, const char *msg) { + captureLogFunc(file, line, ch, msg); +} + +} OutStream::OutStream(const char *file, int line, const char *ch, const char *msg) { m_msg.file = file; @@ -27,10 +41,21 @@ OutStream::OutStream(const char *file, int line, const char *ch, const char *msg } OutStream::~OutStream() { - constexpr std::size_t buffLen = 1024; - std::size_t size = 0; - uint8_t buff[buffLen]; - writeMC(buff, buffLen, &m_msg, &size); + gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str()); +#if defined(OX_USE_STDLIB) + if (OxPrintTrace) { + auto pipe = fopen(OxPrintTrace, "a"); + if (pipe) { + constexpr std::size_t buffLen = 1024; + std::size_t size = 0; + uint8_t buff[buffLen]; + writeMC(buff, buffLen, &m_msg, &size); + + //write(pipe, buff, size); + fclose(pipe); + } + } +#endif } @@ -42,6 +67,7 @@ StdOutStream::StdOutStream(const char *file, int line, const char *ch, const cha } StdOutStream::~StdOutStream() { + gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str()); #if defined(OX_USE_STDLIB) if (OxPrintTrace) { std::cout << std::setw(53) << std::left << m_msg.ch.c_str() << '|'; diff --git a/deps/ox/src/ox/trace/trace.hpp b/deps/ox/src/ox/trace/trace.hpp index afcfc790..ae1dfaca 100644 --- a/deps/ox/src/ox/trace/trace.hpp +++ b/deps/ox/src/ox/trace/trace.hpp @@ -34,6 +34,7 @@ int ioOp(T *io, ox::trace::TraceMsg *obj) { class OutStream { private: + const char *m_delimiter = " "; TraceMsg m_msg; public: @@ -45,11 +46,19 @@ class OutStream { template inline OutStream &operator<<(const T &v) { - m_msg.msg += " "; + m_msg.msg += m_delimiter; m_msg.msg += v; return *this; } + /** + * del sets the delimiter between log segments. + */ + inline OutStream &del(const char *delimiter) { + m_delimiter = delimiter; + return *this; + } + }; @@ -106,7 +115,7 @@ class NullStream { }; #ifdef DEBUG -using TraceStream = StdOutStream; +using TraceStream = OutStream; #else using TraceStream = NullStream; #endif