Defines | Typedefs | Functions

debug log
[LIM utility library]


#define LIM_LOG_MAX_ENTRY_BYTES   2048
#define LIM_LOG_HEX_PRINT_MAX   2048
#define LIM_LOG_BUFFER_BYTES   (1024 * 1024 * 2)
#define LIM_LOG_DISABLED   -1
#define LIM_LOG_FATAL   0
#define LIM_LOG_ERROR   8
#define LIM_LOG_WARNING   16
#define LIM_LOG_INFO   32
#define LIM_LOG_VERBOSE   64
#define LIM_LOG_DEBUG   999
#define LIMLOG(level, descriptor, fmt, arg...)
#define LIMHEX(buf, bytes)
#define LIMFATAL(fmt, arg...)   LIMLOG(LIM_LOG_FATAL, "FATAL", fmt, ##arg)
#define LIMERR(fmt, arg...)   LIMLOG(LIM_LOG_ERROR, "ERROR", fmt, ##arg)
#define LIMWARN(fmt, arg...)   LIMLOG(LIM_LOG_WARNING, "WARNING", fmt, ##arg)
#define LIMDBG(fmt, arg...)   LIMLOG(LIM_LOG_DEBUG, "DEBUG", fmt, ##arg)
#define LIMINFO(fmt, arg...)   LIMLOG(LIM_LOG_INFO, "INFO", fmt, ##arg)
#define LIMVERBOSE(fmt, arg...)   LIMLOG(LIM_LOG_VERBOSE, "VERBOSE", fmt, ##arg)
#define ASSERT(cond)   do { if (!(cond)) LIMFATAL("ASSERT\n"); } while (0)


typedef void(* lim_log_listener_t )(const void *arg, int level, const void *log, int bytes)


int lim_log_init (int bytes, int level, lim_log_listener_t listener, void *arg)
int lim_log (const char *context, int level, const char *fmt,...)
int lim_log_print_hex (const char *context, const void *data, int bytes)
int lim_log_set_level (int level)
int lim_log_get_level (void)
int lim_log_set_listener (lim_log_listener_t listener, void *arg)
int lim_log_read (void *log, int *bytes)
void lim_log_dump (void)

Detailed Description

log support is done in a non-intrusive and light way so that enableing log support itelf won't affect running system much (hopefully).

after being initialized with lim_log_init(), log entry can be added by calling lim_log() to a circular buffer, which can be retrieved at any time by lim_log_read().

log is added only when requested log level is lower than current log level set by client.

upon each log write, client supplied callback is called if present, so client can catch the log and processes it if desirable.

client can choose to completely disable internal log buffer and relies on its own listener to process log entries, by calling to lim_log_init() with zero buffer length.

upon fatal error, system will automatically dump log to 'lim-log.dump', if internal circular buffer is enabled.

default LIM log level: LIM_LOG_INFO.

Define Documentation

#define ASSERT (   cond  )     do { if (!(cond)) LIMFATAL("ASSERT\n"); } while (0)
#define LIM_LOG_BUFFER_BYTES   (1024 * 1024 * 2)

default log circular buffer size in bytes.

#define LIM_LOG_DEBUG   999
#define LIM_LOG_DISABLED   -1
#define LIM_LOG_ERROR   8
#define LIM_LOG_FATAL   0
#define LIM_LOG_HEX_PRINT_MAX   2048

maximum number of bytes allowed when printing in HEX format.

#define LIM_LOG_INFO   32
#define LIM_LOG_MAX_ENTRY_BYTES   2048

maximum number of bytes per log entry.

#define LIM_LOG_VERBOSE   64
#define LIM_LOG_WARNING   16
#define LIMDBG (   fmt,
)    LIMLOG(LIM_LOG_DEBUG, "DEBUG", fmt, ##arg)
#define LIMERR (   fmt,
)    LIMLOG(LIM_LOG_ERROR, "ERROR", fmt, ##arg)
#define LIMFATAL (   fmt,
)    LIMLOG(LIM_LOG_FATAL, "FATAL", fmt, ##arg)
#define LIMHEX (   buf,
do {                                         \
        char context[1024];                                             \
        snprintf(context, 1024, "%s: %s--%s: %d",                       \
                 "HEXDUMP", __BASE_FILE__, __FUNCTION__, __LINE__);     \
        lim_log_print_hex(context, buf, bytes); } while(0)
#define LIMINFO (   fmt,
)    LIMLOG(LIM_LOG_INFO, "INFO", fmt, ##arg)
#define LIMLOG (   level,
do {                     \
        char context[1024];                                             \
        snprintf(context, 1024, "%s: %s--%s: %d",                       \
                 descriptor, __BASE_FILE__, __FUNCTION__, __LINE__);    \
        lim_log(context, level, fmt, ##arg); } while(0)
#define LIMVERBOSE (   fmt,
#define LIMWARN (   fmt,

Typedef Documentation

typedef void(* lim_log_listener_t)(const void *arg, int level, const void *log, int bytes)

LIM Log listener callback type definition. listener is called with log mutex held, it must not block.

arg client supplied callback context.
level log level
log log buffer
bytes log data bytes in buffer.

Function Documentation

int lim_log ( const char *  context,
int  level,
const char *  fmt,

write log entry.

context client supplied context description, can be NULL.
level log message level.
0 if log successfully written, non-zero otherwise.
void lim_log_dump ( void   ) 

dump log to 'lim-log.dump'

int lim_log_get_level ( void   ) 

get current log level.

int lim_log_init ( int  bytes,
int  level,
lim_log_listener_t  listener,
void *  arg 

initialize lim log support. log system can be reinitialized at run time.

bytes maximum log buffer length in bytes. If zero, internal log buffer is disabled. When internal buffer is disabled, it relies on client listener to actually interpret log entries.
level target log level.
listener client log listener if any.
arg client listener callback context.
0 if log support successfully initialized, nonzero error otherwise.
int lim_log_print_hex ( const char *  context,
const void *  data,
int  bytes 

write hex format log entry. dump buffer in hex format to log entry at LIM_LOG_DEBUG level, up to LIM_LOG_HEX_PRINT_MAX bytes at a time.

context client supplied context description, can be NULL.
data data buffer
bytes data buffer length in bytes.
0 if log successfully written, non-zero otherwise.
int lim_log_read ( void *  log,
int *  bytes 

read log circular buffer.

log client supplied buffer.
bytes input as buffer length of user supplied buffer, output as available bytes filled in by the log system.
0 if log successfully read, non-zero otherwise.
int lim_log_set_level ( int  level  ) 

set current log level.

0 if log level successfully set, non-zero otherwise.
int lim_log_set_listener ( lim_log_listener_t  listener,
void *  arg 

set current log listener. only up to one listener is supported, newly set listener will automatically removed previously registered listener if any.

listener client supplied listener callback.
arg client listener callback context.
0 if log listener successfully set, non-zero otherwise.
LIMOpenMAX Implementation API Reference - Generated by doxygen