Logging facility. More...
#include <exception>
#include <syslog.h>
#include <string.h>
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 |
Logging facility.
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.
#define CLDEBUG |
#define CLERROR |
#define CLFATAL |
#define CLINFO |
#define CPLDEBUG |
#define CPLERROR |
#define CPLFATAL |
#define CPLINFO |
#define IDLDEBUG |
#define IDLERROR |
#define IDLFATAL |
#define IDLINFO |
#define IDPLDEBUG |
#define IDPLERROR |
#define IDPLFATAL |
#define IDPLINFO |
#define LBS2 64 |
#define LDEBUG |
#define LERROR |
#define LFATAL |
#define LINFO |
#define PLDEBUG |
#define PLERROR |
#define PLFATAL |
#define PLINFO |
#define REPORT_CURRENT_EXCEPTION report_current_exception(__LINE__, __FILE__) |
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 main(), and NeoBrain::paramChanged().
void report_current_exception | ( | const int | line, | |
const char * | file | |||
) | throw () |
Helper function for REPORT_CURRENT_EXCEPTION macro.
Definition at line 315 of file log.C.
References rutz::demangled_name().
const int LFATAL_PRINTS_ABORT = (1 << 1) |
Make LFATAL() print " -- ABORT" after each message.
This flag is on by default.
Definition at line 131 of file log.H.
Referenced by mexFunction().
const int LFATAL_THROWS = (1 << 0) |
const int LFATAL_XTRA_NOISY = (1 << 2) |
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 mexFunction().
int LOG_FLAGS |
Bitwise-or'ed combination of above flags.
Definition at line 56 of file log.C.
Referenced by main(), mexFunction(), and sendlog().
const int LOG_FULLTRACE = (1 << 3) |
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().
const char* MYLOGPREFIX |
int MYLOGVERB |
Log verbosity (see <syslog.h> for possible values). Default value is LOG_DEBUG. Executables don't need to do anything special unless they need a non-default value.
Definition at line 60 of file log.C.
Referenced by BeoSubSaliency::BeoSubSaliency(), ColorTracker::ColorTracker(), ComplexChannel::combineOutputs(), RawVisualCortex::combineOutputs(), IntegerRawVisualCortex::combineOutputsInt(), IntegerComplexChannel::combineOutputsInt(), SingleChannel::combineSubMaps(), ComplexObject::ComplexObject(), RawVisualCortex::getChannelOutputMap(), SpectralResidualChannel::getOutput(), SingleChannel::getRawCSmap(), IntegerSimpleChannel::getRawCSmapInt(), main(), BeoMap::makePanorama(), mexFunction(), ModelManager::paramChanged(), SingleChannel::postProcessMap(), BeeSTEM::run(), BeoChip::run(), sendlog(), submain(), BeoChip::writeByte(), and BeeSTEM::writeByte().