Classes | Macros | Functions
journaller.h File Reference
#include "journalloglevel.h"
#include "abstractadditionallogger.h"
#include <sstream>
#include <iomanip>
#include <xstypes/xsstring.h>
#include <memory>
Include dependency graph for journaller.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  JlHexLogger< T >
 A support class of journaller that is used for the logging of hex values. More...
 
class  Journaller
 A journalling class for debugging applications. More...
 
class  JournalValueJanitor< T >
 Class for journalling a referenced value when the janitor leaves scope. More...
 

Macros

#define JLALERT(...)   ((void)0)
 
#define JLALERT_NODEC(...)   ((void)0)
 
#define JLALERTG(msg)   JLALERT(gJournal, msg)
 
#define JLCASE(s, a)   case a: s << #a << "(" << static_cast<int>(a) << ")"; break;
 
#define JLCASE2(s, a, b)   case a: s << b << "(" << static_cast<int>(a) << ")"; break;
 
#define JLDEBUG(...)   ((void)0)
 
#define JLDEBUG_NODEC(...)   ((void)0)
 
#define JLDEBUGFINAL(journal, a)   JLFINALVALUE(journal, JLL_Debug, a)
 
#define JLDEBUGFINALG(a)   JLDEBUGFINAL(gJournal, a)
 
#define JLDEBUGG(msg)   JLDEBUG(gJournal, msg)
 
#define JLDEFAULTCASE(s)   default: s << "Unknown case: " << static_cast<int>(e); break;
 
#define JLENUMCASE(a)   JLCASE(dbg, a)
 
#define JLENUMCASE2(a, b)   JLCASE2(dbg, a, b)
 
#define JLENUMCASEBITS(a)   if ((static_cast<int>(e) & static_cast<int>(a)) == static_cast<int>(a)) { if (first) first = false; else dbg << " | "; dbg << #a << "(" << static_cast<int>(a) << ")"; }
 
#define JLENUMCASEBITSNONE(a)   if (first) { dbg << #a << "(0)"; first = false; }
 
#define JLENUMEXPANDER(E, items)   JLENUMEXPHDR(E) items JLENUMEXPFTR()
 
#define JLENUMEXPANDERBITS(E, items)   /*! \brief Translate \a e into a text representation */ JLENUMEXPPROTO(E) { bool first = true; dbg << std::hex << std::uppercase << static_cast<int>(e) << "="; items if (first) dbg << "<None>"; dbg << std::dec << std::nouppercase; return dbg; }
 
#define JLENUMEXPANDERHEX(E, items)   JLENUMEXPHDR(E, dbg << std::hex << std::uppercase;) items JLENUMEXPFTR(dbg << std::dec << std::nouppercase;)
 
#define JLENUMEXPFTR(...)   JLDEFAULTCASE(dbg) } __VA_ARGS__ return dbg; }
 
#define JLENUMEXPHDR(E, ...)   /*! \brief Translate \a e into a text representation */ JLENUMEXPPROTO(E) { __VA_ARGS__ switch(e) {
 
#define JLENUMEXPPROTO(E)   std::ostream& operator << (std::ostream& dbg, E const& e)
 
#define JLERROR(journal, msg)   JLGENERIC(journal, JLL_Error, msg)
 
#define JLERROR_NODEC(journal, msg)   JLGENERIC_NODEC(journal, JLL_Error, msg)
 
#define JLERRORG(msg)   JLERROR(gJournal, msg)
 
#define JLFATAL(journal, msg)   JLGENERIC(journal, JLL_Fatal, msg)
 
#define JLFATAL_NODEC(journal, msg)   JLGENERIC_NODEC(journal, JLL_Fatal, msg)
 
#define JLFATALG(msg)   JLFATAL(gJournal, msg)
 
#define JLFINALNAME(a)   #a ": "
 
#define JLFINALVALUE(journal, level, a)   JournalValueJanitor<decltype(a)> jlFinalValue ## a(journal, a, [](char const* fi, char const* fu, char const* va) { std::stringstream os; os << fi << " " << fu << " exit " << va; return os.str(); }(__FILE__, __FUNCTION__, JLFINALNAME(a)), level, true)
 
#define JLGENERIC(journal, level, msg)
 
#define JLGENERIC_LINEINFO   ""
 
#define JLGENERIC_NODEC(journal, level, msg)
 
#define JLHEXLOG(d)   "0x" << JLHEXLOG_BARE(d)
 
#define JLHEXLOG_BARE(d)   JlHexLogger<decltype(d)>(d)
 
#define JLIF(journal, level, todo)   do { if (journal && journal->logLevel(level)) { todo; } } while(0)
 
#define JLINSTALLQTDEBUGHANDLER(journal)
 
#define JLPRECISE(msg)   JLPRECISE2(msg, 16)
 
#define JLPRECISE2(msg, prec)
 
#define JLQTDEBUGHANDLER
 
#define JLTRACE(...)   ((void)0)
 
#define JLTRACE_NODEC(...)   ((void)0)
 
#define JLTRACEG(msg)   JLTRACE(gJournal, msg)
 
#define JLVARLOG(a)   #a ": " << a << " "
 
#define JLWRITE(journal, msg)   JLGENERIC(journal, JLL_Write, msg)
 
#define JLWRITE_NODEC(journal, msg)   JLGENERIC_NODEC(journal, JLL_Write, msg)
 
#define JLWRITEFINAL(journal, a)   JLFINALVALUE(journal, JLL_Write, a)
 
#define JLWRITEFINALG(a)   JLWRITEFINAL(gJournal, a)
 
#define JLWRITEG(msg)   JLWRITE(gJournal, msg)
 
#define STRIPPEDFILE   jlStrippedPathFile(__FILE__)
 

Functions

static constexpr char const * jlStrippedPath (char const *a, char const *b)
 
static constexpr char const * jlStrippedPathFile (char const *a)
 
void jlTerminate (Journaller **gj)
 Cleans up any remaining stuff. More...
 
template<>
std::ostream & operator<< (std::ostream &os, JlHexLogger< char > const &hex)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, JlHexLogger< T > const &hex)
 

Macro Definition Documentation

◆ JLALERT

#define JLALERT (   ...)    ((void)0)

Definition at line 247 of file journaller.h.

◆ JLALERT_NODEC

#define JLALERT_NODEC (   ...)    ((void)0)

Definition at line 248 of file journaller.h.

◆ JLALERTG

#define JLALERTG (   msg)    JLALERT(gJournal, msg)

Definition at line 281 of file journaller.h.

◆ JLCASE

#define JLCASE (   s,
 
)    case a: s << #a << "(" << static_cast<int>(a) << ")"; break;

Definition at line 348 of file journaller.h.

◆ JLCASE2

#define JLCASE2 (   s,
  a,
 
)    case a: s << b << "(" << static_cast<int>(a) << ")"; break;

Definition at line 347 of file journaller.h.

◆ JLDEBUG

#define JLDEBUG (   ...)    ((void)0)

Definition at line 239 of file journaller.h.

◆ JLDEBUG_NODEC

#define JLDEBUG_NODEC (   ...)    ((void)0)

Definition at line 240 of file journaller.h.

◆ JLDEBUGFINAL

#define JLDEBUGFINAL (   journal,
 
)    JLFINALVALUE(journal, JLL_Debug, a)

Definition at line 292 of file journaller.h.

◆ JLDEBUGFINALG

#define JLDEBUGFINALG (   a)    JLDEBUGFINAL(gJournal, a)

Definition at line 293 of file journaller.h.

◆ JLDEBUGG

#define JLDEBUGG (   msg)    JLDEBUG(gJournal, msg)

Definition at line 280 of file journaller.h.

◆ JLDEFAULTCASE

#define JLDEFAULTCASE (   s)    default: s << "Unknown case: " << static_cast<int>(e); break;

Definition at line 349 of file journaller.h.

◆ JLENUMCASE

#define JLENUMCASE (   a)    JLCASE(dbg, a)

Definition at line 352 of file journaller.h.

◆ JLENUMCASE2

#define JLENUMCASE2 (   a,
 
)    JLCASE2(dbg, a, b)

Definition at line 353 of file journaller.h.

◆ JLENUMCASEBITS

#define JLENUMCASEBITS (   a)    if ((static_cast<int>(e) & static_cast<int>(a)) == static_cast<int>(a)) { if (first) first = false; else dbg << " | "; dbg << #a << "(" << static_cast<int>(a) << ")"; }

Definition at line 366 of file journaller.h.

◆ JLENUMCASEBITSNONE

#define JLENUMCASEBITSNONE (   a)    if (first) { dbg << #a << "(0)"; first = false; }

Definition at line 367 of file journaller.h.

◆ JLENUMEXPANDER

#define JLENUMEXPANDER (   E,
  items 
)    JLENUMEXPHDR(E) items JLENUMEXPFTR()

Use this macro to define enum expansion to a text stream, items will show up as "EnumName (decimal value)". supply the type as parameter E and all enum values you want to expand as a sequence of JLENUMCASE(item) (no commas)

Definition at line 357 of file journaller.h.

◆ JLENUMEXPANDERBITS

#define JLENUMEXPANDERBITS (   E,
  items 
)    /*! \brief Translate \a e into a text representation */ JLENUMEXPPROTO(E) { bool first = true; dbg << std::hex << std::uppercase << static_cast<int>(e) << "="; items if (first) dbg << "<None>"; dbg << std::dec << std::nouppercase; return dbg; }

Use this macro to define enum bit field expansion to a text stream, items will show up as "full hex=EnumName1(hex) | EnumName2(hex)". supply the type as parameter E and all enum values you want to expand as a sequence of JLENUMCASEBITS(item) (no commas)

Definition at line 365 of file journaller.h.

◆ JLENUMEXPANDERHEX

#define JLENUMEXPANDERHEX (   E,
  items 
)    JLENUMEXPHDR(E, dbg << std::hex << std::uppercase;) items JLENUMEXPFTR(dbg << std::dec << std::nouppercase;)

Use this macro to define enum expansion to a text stream, items will show up as "EnumName (hexadecimal value)". supply the type as parameter E and all enum values you want to expand as a sequence of JLENUMCASE(item) (no commas)

Definition at line 361 of file journaller.h.

◆ JLENUMEXPFTR

#define JLENUMEXPFTR (   ...)    JLDEFAULTCASE(dbg) } __VA_ARGS__ return dbg; }

Definition at line 354 of file journaller.h.

◆ JLENUMEXPHDR

#define JLENUMEXPHDR (   E,
  ... 
)    /*! \brief Translate \a e into a text representation */ JLENUMEXPPROTO(E) { __VA_ARGS__ switch(e) {

Definition at line 351 of file journaller.h.

◆ JLENUMEXPPROTO

#define JLENUMEXPPROTO (   E)    std::ostream& operator << (std::ostream& dbg, E const& e)

Definition at line 350 of file journaller.h.

◆ JLERROR

#define JLERROR (   journal,
  msg 
)    JLGENERIC(journal, JLL_Error, msg)

Definition at line 258 of file journaller.h.

◆ JLERROR_NODEC

#define JLERROR_NODEC (   journal,
  msg 
)    JLGENERIC_NODEC(journal, JLL_Error, msg)

Definition at line 259 of file journaller.h.

◆ JLERRORG

#define JLERRORG (   msg)    JLERROR(gJournal, msg)

Definition at line 282 of file journaller.h.

◆ JLFATAL

#define JLFATAL (   journal,
  msg 
)    JLGENERIC(journal, JLL_Fatal, msg)

Definition at line 266 of file journaller.h.

◆ JLFATAL_NODEC

#define JLFATAL_NODEC (   journal,
  msg 
)    JLGENERIC_NODEC(journal, JLL_Fatal, msg)

Definition at line 267 of file journaller.h.

◆ JLFATALG

#define JLFATALG (   msg)    JLFATAL(gJournal, msg)

Definition at line 283 of file journaller.h.

◆ JLFINALNAME

#define JLFINALNAME (   a)    #a ": "

Definition at line 288 of file journaller.h.

◆ JLFINALVALUE

#define JLFINALVALUE (   journal,
  level,
 
)    JournalValueJanitor<decltype(a)> jlFinalValue ## a(journal, a, [](char const* fi, char const* fu, char const* va) { std::stringstream os; os << fi << " " << fu << " exit " << va; return os.str(); }(__FILE__, __FUNCTION__, JLFINALNAME(a)), level, true)

Definition at line 289 of file journaller.h.

◆ JLGENERIC

#define JLGENERIC (   journal,
  level,
  msg 
)
Value:
do { /*lint --e{506}*/ \
if (journal && journal->logLevel(level)) \
{ \
std::ostringstream os; \
os << JLGENERIC_LINEINFO << __FUNCTION__ << " " << msg; \
journal->log(level, os.str()); \
} \
{ \
std::ostringstream os; \
os << msg; \
Journaller::additionalLogger()->log(level, STRIPPEDFILE, __LINE__, __FUNCTION__, os.str()); \
} \
} while(0)

Definition at line 196 of file journaller.h.

◆ JLGENERIC_LINEINFO

#define JLGENERIC_LINEINFO   ""

Definition at line 193 of file journaller.h.

◆ JLGENERIC_NODEC

#define JLGENERIC_NODEC (   journal,
  level,
  msg 
)
Value:
do { \
if (journal && journal->logLevel(level)) \
{ \
std::ostringstream os; \
os << msg << '\n'; \
journal->writeMessage(os.str()); \
} \
{ \
std::ostringstream os; \
os << msg << '\n'; \
Journaller::additionalLogger()->logNoDecoration(level, STRIPPEDFILE, __LINE__, __FUNCTION__, os.str()); \
} \
} while(0)

Definition at line 212 of file journaller.h.

◆ JLHEXLOG

#define JLHEXLOG (   d)    "0x" << JLHEXLOG_BARE(d)

Definition at line 335 of file journaller.h.

◆ JLHEXLOG_BARE

#define JLHEXLOG_BARE (   d)    JlHexLogger<decltype(d)>(d)

Definition at line 331 of file journaller.h.

◆ JLIF

#define JLIF (   journal,
  level,
  todo 
)    do { if (journal && journal->logLevel(level)) { todo; } } while(0)

Definition at line 298 of file journaller.h.

◆ JLINSTALLQTDEBUGHANDLER

#define JLINSTALLQTDEBUGHANDLER (   journal)
Value:
qtJournal = journal;\
if (journal) {\
if (gOldQtMessageHandler == NULL) gOldQtMessageHandler = qInstallMessageHandler(jlQtMessageHandler);\
else qInstallMessageHandler(jlQtMessageHandler);\
} else if (gOldQtMessageHandler) {\
qInstallMessageHandler(gOldQtMessageHandler);\
gOldQtMessageHandler = NULL;\
}

Definition at line 396 of file journaller.h.

◆ JLPRECISE

#define JLPRECISE (   msg)    JLPRECISE2(msg, 16)

Definition at line 345 of file journaller.h.

◆ JLPRECISE2

#define JLPRECISE2 (   msg,
  prec 
)
Value:
[&](){\
std::ostringstream os; \
os.precision(prec); \
os << msg; \
return os.str();\
}()

Definition at line 338 of file journaller.h.

◆ JLQTDEBUGHANDLER

#define JLQTDEBUGHANDLER
Value:
QtMessageHandler gOldQtMessageHandler = nullptr; \
Journaller* qtJournal = nullptr; \
QtMessageHandler qtChecker = nullptr; \
void jlQtMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {\
if (qtChecker) qtChecker(type, context, msg); \
if (!qtJournal) return;\
switch (type) {\
case QtDebugMsg:\
JLDEBUG(qtJournal, (const char *)msg.toLatin1());\
break;\
case QtWarningMsg:\
JLALERT(qtJournal, (const char *)msg.toLatin1());\
break;\
case QtCriticalMsg:\
JLERROR(qtJournal, (const char *)msg.toLatin1());\
break;\
case QtFatalMsg:\
JLFATAL(qtJournal, (const char *)msg.toLatin1());\
abort();\
default:\
break;\
}\
if (gOldQtMessageHandler)\
gOldQtMessageHandler(type,context,msg);\
}

Definition at line 369 of file journaller.h.

◆ JLTRACE

#define JLTRACE (   ...)    ((void)0)

Definition at line 231 of file journaller.h.

◆ JLTRACE_NODEC

#define JLTRACE_NODEC (   ...)    ((void)0)

Definition at line 232 of file journaller.h.

◆ JLTRACEG

#define JLTRACEG (   msg)    JLTRACE(gJournal, msg)

Definition at line 279 of file journaller.h.

◆ JLVARLOG

#define JLVARLOG (   a)    #a ": " << a << " "

Definition at line 336 of file journaller.h.

◆ JLWRITE

#define JLWRITE (   journal,
  msg 
)    JLGENERIC(journal, JLL_Write, msg)

Definition at line 274 of file journaller.h.

◆ JLWRITE_NODEC

#define JLWRITE_NODEC (   journal,
  msg 
)    JLGENERIC_NODEC(journal, JLL_Write, msg)

Definition at line 275 of file journaller.h.

◆ JLWRITEFINAL

#define JLWRITEFINAL (   journal,
 
)    JLFINALVALUE(journal, JLL_Write, a)

Definition at line 290 of file journaller.h.

◆ JLWRITEFINALG

#define JLWRITEFINALG (   a)    JLWRITEFINAL(gJournal, a)

Definition at line 291 of file journaller.h.

◆ JLWRITEG

#define JLWRITEG (   msg)    JLWRITE(gJournal, msg)

Definition at line 284 of file journaller.h.

◆ STRIPPEDFILE

#define STRIPPEDFILE   jlStrippedPathFile(__FILE__)

Definition at line 185 of file journaller.h.

Function Documentation

◆ jlStrippedPath()

static constexpr char const* jlStrippedPath ( char const *  a,
char const *  b 
)
inlinestaticconstexpr

Definition at line 177 of file journaller.h.

◆ jlStrippedPathFile()

static constexpr char const* jlStrippedPathFile ( char const *  a)
inlinestaticconstexpr

Definition at line 181 of file journaller.h.

◆ jlTerminate()

void jlTerminate ( Journaller **  gj)

Cleans up any remaining stuff.

The function assumes that no new log lines will be created anymore

Parameters
gjOptional pointer to Journaller pointer to be cleaned up, usually &gJournal should be provided. The pointer that gj points to will be set to nullptr.
Note
JLINSTALLQTDEBUGHANDLER(0) is not done as it would create a dependency on Qt so you need to call that yourself before calling jlTerminate

Definition at line 505 of file journaller.cpp.

◆ operator<<() [1/2]

template<>
std::ostream& operator<< ( std::ostream &  os,
JlHexLogger< char > const &  hex 
)

Definition at line 388 of file journaller.cpp.

◆ operator<<() [2/2]

template<typename T >
std::ostream& operator<< ( std::ostream &  os,
JlHexLogger< T > const &  hex 
)

Definition at line 323 of file journaller.h.

msg
msg
AbstractAdditionalLogger::log
virtual void log(JournalLogLevel level, char const *file, int line, char const *function, std::string const &msg)=0
Write line to the log.
JLGENERIC_LINEINFO
#define JLGENERIC_LINEINFO
Definition: journaller.h:193
STRIPPEDFILE
#define STRIPPEDFILE
Definition: journaller.h:185
Journaller::hasAdditionalLogger
static bool hasAdditionalLogger()
Definition: journaller.h:140
AbstractAdditionalLogger::logNoDecoration
virtual void logNoDecoration(JournalLogLevel level, char const *file, int line, char const *function, std::string const &msg)=0
Write line to the log without decoration (timestamp, thread)
Journaller::additionalLogger
static AbstractAdditionalLogger * additionalLogger()
Definition: journaller.h:146


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:21