
This is a comprehensive logging facility. Use the functions provided below to display messages to the user and/or syslog. Never use printf() or std::cout<< in your code, use the functions provided here instead.
Basic function call is [ID | C][P]L<LOGLEV>("format", args, ...)
Although macros, all functions are atomic, so 'if (bad) LERROR(bad);' is ok; also arguments that span several lines of source code are ok too. Using these functions in macros however is probably bogus: MACRO(LERROR("xx")). CAUTION: message size is limited to LBS chars (including final ''); longer messages will be cleanly truncated.
All log functions act like printf, so be careful when passing strings from outside directly as the format string for these functions, as outside strings may contain '' signs which could segfault your program! so, use LERROR("%s", unknown_string) rather than LERROR(unknown_string).
DEBUG, INFO and ERROR simply report an error. FATAL also throws an exception of class "bug" (or exits; see implementation).
Log entries will look like:
>>>>>>>>>>>>>>>>>>>> LERROR("success! %d %s", 10, "bozo")
Jan 11 07:21:26 jukebox dntwebcfgd: SockServ::check: success! 10 bozo
^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^ ^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^
date/time machine program class funct message
>>>>>>>>>>>>>>>>>>>> PLERROR("Cannot open");
Jan 11 07:21:26 jukebox dntwebcfg: Cool::check: Cannot open (Bad descriptor)
^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^ ^^^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
date/time machine program class funct message errno in clear
>>>>>>>>>>>>>>>>>>>> IDLINFO("Connected");
with '#define MYLOGID fd' and current value of fd being 10
Jan 11 07:21:26 jukebox dntwebcfgd: Cool::check:(10) Connected
^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^ ^^ ^^^^^^^^^
date/time machine program class funct ID message
>>>>>>>>>>>>>>>>>>>> IDPLFATAL("Abort");
with '#define MYLOGID fd' and current value of fd being 10
Jan 11 07:21:26 jukebox dntwebcfgd: Cool::check:(10) Abort (Out of memory)
^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^
date/time machine program class funct ID mes errno in clear
>>>>>>>>>>>>>>>>>>>> CLERROR("success! %d %s", 10, "bozo")
Jan 11 07:21:26 jukebox dntwebcfgd: [Gabor(45)]::check: success! 10 bozo
^^^^^^^^^^^^^^^ ^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^
date/time machine program ModelComponent funct message
If the message starts with a '(', '[' or '{' char, no space is written between the colon following function name and the message
A last macro is provided, SHOWMEMORY(format, ...) which will display your message via LERROR, and append the total memory usage for the current process (as per the VmSize field in /proc/<pid>/status; this is useful to check for possible memory leaks). It only works under Linux and hence we have only defined it in the GNU C section here.
Definition in file log.H.
#include <exception>
#include <syslog.h>
#include <string.h>
Include dependency graph for log.H:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Classes | |
| class | lfatal_exception |
| Type of exception that is thrown from LFATAL if (LOG_FLAGS&LFATAL_THROWS). More... | |
Defines | |
| #define | LBS2 64 |
| max size of function or file name | |
| #define | SENDLOG MYLOG_USEID=false, MYLOG_USEP=false, sendlog |
| #define | SENDPLOG MYLOG_USEID=false, MYLOG_USEP=true, sendlog |
| #define | SENDIDLOG MYLOG_USEID=true, MYLOG_USEP=false, sendlog |
| #define | SENDIDPLOG MYLOG_USEID=true, MYLOG_USEP=true, sendlog |
| #define | LDEBUG |
| #define | LINFO |
| #define | LERROR |
| #define | LFATAL |
| #define | PLDEBUG |
| #define | PLINFO |
| #define | PLERROR |
| #define | PLFATAL |
| #define | IDLDEBUG |
| #define | IDLINFO |
| #define | IDLERROR |
| #define | IDLFATAL |
| #define | IDPLDEBUG |
| #define | IDPLINFO |
| #define | IDPLERROR |
| #define | IDPLFATAL |
| #define | CLOGFILE ("[" + descriptiveName() + "]").c_str() |
| #define | CLDEBUG |
| #define | CLINFO |
| #define | CLERROR |
| #define | CLFATAL |
| #define | CPLDEBUG |
| #define | CPLINFO |
| #define | CPLERROR |
| #define | CPLFATAL |
| #define | REPORT_CURRENT_EXCEPTION report_current_exception(__LINE__, __FILE__) |
| Use this inside of a catch(...) to report info about the caught exception. | |
Functions | |
| void | sendlog (const char *msg,...) __attribute__((format(__printf__ |
| void | report_current_exception (const int line, const char *file) throw () |
| Helper function for REPORT_CURRENT_EXCEPTION macro. | |
Variables | |
| const int | LFATAL_THROWS = (1 << 0) |
| Make LFATAL() throw a std::exception rather than abort()ing. | |
| const int | LFATAL_PRINTS_ABORT = (1 << 1) |
| Make LFATAL() print " -- ABORT" after each message. | |
| const int | LFATAL_XTRA_NOISY = (1 << 2) |
| Make LFATAL() print its msg to stderr/syslog AND put it in the std::exception. | |
| const int | LOG_FULLTRACE = (1 << 3) |
| Whether to send log messages to stderr or to syslog. | |
| int | LOG_FLAGS |
| Bitwise-or'ed combination of above flags. | |
| int | MYLOGVERB |
| const char * | MYLOGPREFIX |
| Null by default, but if set to non-null this string will be prefixed to every log message. | |
| void char | MYLOGFUN [] |
| void char | MYLOGFIL [] |
| int | MYLOGLIN |
| int | MYLOGLEV |
| int | MYLOGIDVAL |
| bool | MYLOG_USEID |
| bool | MYLOG_USEP |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ strncpy(MYLOGFIL, CLOGFILE, LBS2-1),MYLOGLEV=LOG_DEBUG,SENDLOG Definition at line 319 of file log.H. Referenced by ModelComponent::exportOptions(), SaccadeController::getDecision(), SingleOpponentChannel::getFeatures(), SingleChannel::getFeatures(), SingleOpponentChannel::getFeaturesBatch(), SingleChannel::getFeaturesBatch(), ModelComponent::ModelComponent(), SaccadeController::resetPos(), ModelComponent::start(), BeoChip::start1(), ModelComponent::stop(), and ModelComponent::~ModelComponent(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ strncpy(MYLOGFIL, CLOGFILE, LBS2-1),MYLOGLEV=LOG_ERR,SENDLOG Definition at line 323 of file log.H. Referenced by ModelComponent::doRequestOption(), BeoSubBallast::input(), ModelComponent::removeSubComponent(), and ModelComponent::unregisterParam(). |
|
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ strncpy(MYLOGFIL, CLOGFILE, LBS2-1),MYLOGLEV=LOG_INFO,SENDLOG Definition at line 321 of file log.H. Referenced by SaccadeController::dumpQueues(), SaccadeController::getDecision(), BeoSubBallast::input(), BeoSubBallast::mechanicalInitialize(), BeoSubTwoBal::start2(), BeoSubSim::start2(), and BeoSubOneBal::start2(). |
|
|
Value: |
|
|
Value: |
|
|
Value: |
|
|
Value: |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_DEBUG,\ SENDIDLOG Definition at line 291 of file log.H. Referenced by SockServ::addClient(), SockServ::check(), TCPcommunicator::contact(), SockServ::disconnect(), TCPcliServ::init(), and SockServ::~SockServ(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_ERR,\ SENDIDLOG Definition at line 297 of file log.H. Referenced by SockServ::check(), SockServ::getClientIP(), and SockServ::getClientPort(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_CRIT,\ SENDIDLOG Definition at line 300 of file log.H. Referenced by SockServ::check(), and V4Lgrabber::start1(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_INFO,\ SENDIDLOG Definition at line 294 of file log.H. Referenced by V4Lgrabber::start1(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_DEBUG,\ SENDIDPLOG Definition at line 304 of file log.H. Referenced by SockServ::check(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_ERR,\ SENDIDPLOG Definition at line 310 of file log.H. Referenced by SockServ::check(), TCPcommunicator::contact(), TCPcliServ::init(), V4Lgrabber::start1(), and TCPcliServ::~TCPcliServ(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_CRIT,\ SENDIDPLOG Definition at line 313 of file log.H. Referenced by TCPcliServ::check(), V4Lgrabber::grabRaw(), V4Lgrabber::grabSingleRaw(), and V4Lgrabber::start1(). |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ MYLOGIDVAL=MYLOGID,strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_INFO,\ SENDIDPLOG |
|
|
max size of function or file name
Definition at line 265 of file log.H. Referenced by sendlog(). |
|
|
|
|
Value: |
|
|
Value: |
|
|
Value: MYLOGLIN=__LINE__,strncpy(MYLOGFUN, __FUNCTION__, LBS2-1),\ strncpy(MYLOGFIL, __FILE__, LBS2-1),MYLOGLEV=LOG_DEBUG,SENDPLOG Definition at line 282 of file log.H. Referenced by V4Lgrabber::grabRaw(), and V4Lgrabber::grabSingleRaw(). |
|
|
Value: |
|
|
Value: |
|
|
Value: |
|
|
Use this inside of a catch(...) to report info about the caught exception. There MUST be a current exception object in order for this to work (i.e., you must be inside of a catch block when you call REPORT_CURRENT_EXCEPTION). Definition at line 359 of file log.H. Referenced by PrefItemMPStr::fromString(), PrefItemMPNum< MP, T >::fromString(), main(), NeoBrain::paramChanged(), MPlayerWrapper::run(), and Streamer::run(). |
|
||||||||||||
|
Helper function for REPORT_CURRENT_EXCEPTION macro.
Definition at line 315 of file log.C. References rutz::demangled_name(), and e. |
|
|
Make LFATAL() print " -- ABORT" after each message. This flag is on by default. Definition at line 131 of file log.H. Referenced by main(), mexFunction(), and sendlog_aux(). |
|
|
Make LFATAL() throw a std::exception rather than abort()ing. This flag is on by default. Definition at line 128 of file log.H. Referenced by main(), and sendlog_aux(). |
|
|
Make LFATAL() print its msg to stderr/syslog AND put it in the std::exception. This flag is on by default. Without it, LFATAL will only print its message to stderr or syslog if it will NOT be throwing a std::exception with that same message in std::exception::what(). Definition at line 137 of file log.H. Referenced by main(), mexFunction(), and sendlog_aux(). |
|
|
Bitwise-or'ed combination of above flags.
Definition at line 56 of file log.C. Referenced by main(), mexFunction(), and sendlog(). |
|
|
Whether to send log messages to stderr or to syslog. Messages are sent to stderr if the LOG_FULLTRACE flag is set in LOG_FLAGS (this is the default), or are sent to syslog if the LOG_FULLTRACE flag is not set. Executables don't need to do anything special unless they need a non-default value. Definition at line 143 of file log.H. Referenced by main(), mexFunction(), sendlog_aux(), and submain(). |
|
|
Null by default, but if set to non-null this string will be prefixed to every log message. This can be useful if you have multiple threads or multiple processes all writing to stdout, and you want to have some way to distinguish their log messages. Definition at line 66 of file log.C. Referenced by handlesignal(), run_master(), run_slave(), and sendlog_aux(). |
|
1.4.4