Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
Macros | Typedefs | Functions | Variables
Logging

Description

Macros for logging.

Collaboration diagram for Logging:

Macros

#define DEBUG(LEVEL, MSG)   do { if (envDebug >= LEVEL) { LogPara ("DEBUG-" #LEVEL, __FILE__, __LINE__); LogPrintf (MSG); } } while (0)
 Print a debug message. This is only effective if the tool was compiled with WITH_DEBUG == 1 and the configuration parameter 'debug' is set to a value > 0. More...
 
#define DEBUGF(LEVEL, FMT)   do { if (envDebug >= LEVEL) { LogPara ("DEBUG-" #LEVEL, __FILE__, __LINE__); LogPrintf FMT; } } while (0)
 Print a formatted debug message. The argument must contain a parantheses with arguments, which will then be passed to a printf() function variant. For example: DEBUGF(("Current value is %i", my_value))
 
#define INFO(MSG)   do { LogPara ("INFO", __FILE__, __LINE__); LogPrintf (MSG); } while (0)
 Print a debug message to the console.
 
#define INFOF(FMT)   do { LogPara ("INFO", __FILE__, __LINE__); LogPrintf FMT; } while (0)
 Print a formatted info message.
 
#define WARNING(MSG)   do { LogPara ("WARNING", __FILE__, __LINE__); LogPrintf (MSG); } while (0)
 Print a warning message to the console.
 
#define WARNINGF(FMT)   do { LogPara ("WARNING", __FILE__, __LINE__); LogPrintf FMT; } while (0)
 Print a formatted warning message.
 
#define SECURITY(MSG)   do { LogPara ("SECURITY", __FILE__, __LINE__); LogPrintf (MSG); } while (0)
 Print a security-related warning to the console. These are warnings an adminstrator should regularly check out for, since they may be caused by an attack.
 
#define SECURITYF(FMT)   do { LogPara ("SECURITY", __FILE__, __LINE__); LogPrintf FMT; } while (0)
 Print a formatted security-related warning.
 
#define ERROR(MSG)   do { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf (MSG); _exit (3); } while (0)
 Print an error message to the console and quit the application.
 
#define ERRORF(FMT)   do { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf FMT; _exit (3); } while (0)
 Print a formatted error message to the console and quit the application.
 
#define ABORT(MSG)   do { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf (MSG); abort (); } while (0)
 Print an error message to the console and abort the application. Unlike ERROR, this uses the abort() system call, which may generate a core dump to be used for debugging.
 
#define ABORTF(FMT)   do { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf FMT; abort (); } while (0)
 Print a formatted error message to the console and abort the application.
 
#define ASSERT(COND)   do { if (!(COND)) { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf ("Assertion failed"); LogStack (); abort (); } } while (0)
 Check a condition and abort the application if not true.
 
#define ASSERTM(COND, MSG)   do { if (!(COND)) { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf ("Assertion failed: %s", MSG); LogStack (); abort (); } } while (0)
 Check a condition and, if not true, abort the application with a message.
 
#define ASSERTF(COND, FMT)   do { if (!(COND)) { LogPara ("ERROR", __FILE__, __LINE__); LogPrintf ("Assertion failed - explanation follows."); LogPrintf FMT; abort (); LogStack (); abort (); } } while (0)
 Check a condition and, if not true, abort the application with a message.
 
#define ASSERT_WARN(COND)   do { if (!(COND)) WARNING("Weak assertion failed"); } while (0)
 Check a condition and emit a warning if not true.
 

Typedefs

typedef void FLogCbMessage(const char *title, const char *msg)
 Callback to display a message box using OS mechanisms. This is mainly used if the program is aborted using an ERROR... or ABORT... macro and presently only supported on Android.
 
typedef void FLogCbToast(const char *msg, bool showLonger)
 Callback to display a short info popup using OS mechanisms. This is used if for messages printed using an INFO... macro, where the message is preceeded by "-t- " (short toast) or "-T- " (long toast). Toasts are presently only supported on Android.
 

Functions

void LogToSyslog (const char *instanceName=NULL)
 Redirect logging to syslog from now; instance name must be passed if this is called before EnvInit()
 
void LogStack ()
 Log a stack trace (requires linker flag '-rdynamic' to print function names)
 

Variables

int envDebug
 Debug level (read-only; may also be mapped to a constant macro).
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   LEVEL,
  MSG 
)    do { if (envDebug >= LEVEL) { LogPara ("DEBUG-" #LEVEL, __FILE__, __LINE__); LogPrintf (MSG); } } while (0)

Print a debug message. This is only effective if the tool was compiled with WITH_DEBUG == 1 and the configuration parameter 'debug' is set to a value > 0.

Conventions for the debug level (examples):

  • 1: Everything which does not flood the log files
  • 2: GPIO value changes; Temporary outputs
  • 3: Details: Network conversation (Resources), debug output of underlying libs (ALSA, GStreamer, PJSIP, Linphone)

Messages of level 3 or more must have a topic-related prefix "[<topic>]" to allow later filtering,

Definition at line 225 of file base.H.