[ox] Add gdblogger integration
This commit is contained in:
parent
4b70330710
commit
f21cb465e6
12
deps/ox/.gdblogger.json
vendored
Normal file
12
deps/ox/.gdblogger.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
28
deps/ox/src/ox/trace/trace.cpp
vendored
28
deps/ox/src/ox/trace/trace.cpp
vendored
@ -9,6 +9,8 @@
|
||||
#if defined(OX_USE_STDLIB)
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ox/mc/write.hpp>
|
||||
@ -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() {
|
||||
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() << '|';
|
||||
|
13
deps/ox/src/ox/trace/trace.hpp
vendored
13
deps/ox/src/ox/trace/trace.hpp
vendored
@ -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<typename T>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user