LogMacros

Makes LogWriter service more accessible with simple defined macros.

Summary
LogMacrosMakes LogWriter service more accessible with simple defined macros.
CopyrightThis program is free software.
Files
C-kern/api/io/writer/log/log_macros.hHeader file of LogMacros.
Functions
query
GETBUFFER_LOGReturns C-string of buffered log and its length.
COMPARE_LOGCompare logbuffer[size] to buffered log entries.
GETSTATE_LOGReturns log_state_e for LOGCHANNEL.
change
CLEARBUFFER_LOGClears log buffer (sets length of logbuffer to 0).
FLUSHBUFFER_LOGWrites content of internal buffer and then clears it.
SETSTATE_LOGSets LOGSTATE for LOGCHANNEL.
log-text
PRINTF_LOGLogs a generic printf type format string.
PRINTTEXT_LOGLogs a text resource string.
PRINTTEXT_NOARG_LOGLogs a text resource string.
log-variables
PRINTVAR_LOGLogs “<varname>=varvalue” of a variable with name varname.
PRINTARRAYFIELD_LOGLog value of variable stored in array at offset i.
PRINTCSTR_LOGLog “name=value” of string variable.
PRINTINT_LOGLog “name=value” of int variable.
PRINTINT64_LOGLog “name=value” of int64_t variable.
PRINTSIZE_LOGLog “name=value” of size_t variable.
PRINTUINT8_LOGLog “name=value” of uint8_t variable.
PRINTUINT16_LOGLog “name=value” of uint16_t variable.
PRINTUINT32_LOGLog “name=value” of uint32_t variable.
PRINTUINT64_LOGLog “name=value” of uint64_t variable.
PRINTPTR_LOGLog “name=value” of pointer variable.
PRINTDOUBLE_LOGLog “name=value” of double or float variable.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/io/writer/log/log_macros.h

Header file of LogMacros.

Functions

Summary
query
GETBUFFER_LOGReturns C-string of buffered log and its length.
COMPARE_LOGCompare logbuffer[size] to buffered log entries.
GETSTATE_LOGReturns log_state_e for LOGCHANNEL.
change
CLEARBUFFER_LOGClears log buffer (sets length of logbuffer to 0).
FLUSHBUFFER_LOGWrites content of internal buffer and then clears it.
SETSTATE_LOGSets LOGSTATE for LOGCHANNEL.
log-text
PRINTF_LOGLogs a generic printf type format string.
PRINTTEXT_LOGLogs a text resource string.
PRINTTEXT_NOARG_LOGLogs a text resource string.
log-variables
PRINTVAR_LOGLogs “<varname>=varvalue” of a variable with name varname.
PRINTARRAYFIELD_LOGLog value of variable stored in array at offset i.
PRINTCSTR_LOGLog “name=value” of string variable.
PRINTINT_LOGLog “name=value” of int variable.
PRINTINT64_LOGLog “name=value” of int64_t variable.
PRINTSIZE_LOGLog “name=value” of size_t variable.
PRINTUINT8_LOGLog “name=value” of uint8_t variable.
PRINTUINT16_LOGLog “name=value” of uint16_t variable.
PRINTUINT32_LOGLog “name=value” of uint32_t variable.
PRINTUINT64_LOGLog “name=value” of uint64_t variable.
PRINTPTR_LOGLog “name=value” of pointer variable.
PRINTDOUBLE_LOGLog “name=value” of double or float variable.

query

GETBUFFER_LOG

#define GETBUFFER_LOG(
    LOGCHANNEL,
   /*out char ***/buffer,
   /*out size_t **/size
) log_maincontext().iimpl->getbuffer(log_maincontext().object, LOGCHANNEL, buffer, size)

Returns C-string of buffered log and its length.  See also <getbuffer_logwriter>.

Parameter

LOGCHANNELThe number of the log channel - see log_channel_e.
bufferContains pointer to C string after return.  Must have type (char**).  The string is terminated with a 0 byte.
sizeContains size of of C string after return.  The does does not include the 0 byte.

COMPARE_LOG

#define COMPARE_LOG(
    LOGCHANNEL,
    /*size_t*/size,
   /*const char[size]*/logbuffer
) log_maincontext().iimpl->compare(log_maincontext().object, LOGCHANNEL, size, logbuffer)

Compare logbuffer[size] to buffered log entries.  Returns 0 if they are equal (timestamps are ignored during comparison).  See also <compare_logwriter>.

Parameter

LOGCHANNELThe number of the log channel - see log_channel_e.
logsizeContains size of logbuffer.
bufferContains pointer to the logbuffer in memory which is compared to the internal buffer.

GETSTATE_LOG

#define GETSTATE_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->getstate(log_maincontext().object, LOGCHANNEL)

Returns log_state_e for LOGCHANNEL.

Parameter

LOGCHANNELThe number of the log channel - see log_channel_e.

change

CLEARBUFFER_LOG

#define CLEARBUFFER_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->clearbuffer(log_maincontext().object, LOGCHANNEL)

Clears log buffer (sets length of logbuffer to 0).  See also <clearbuffer_logwriter>.

FLUSHBUFFER_LOG

#define FLUSHBUFFER_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->flushbuffer(log_maincontext().object, LOGCHANNEL)

Writes content of internal buffer and then clears it.  See also <flushbuffer_logwriter>.

SETSTATE_LOG

#define SETSTATE_LOG(
   LOGCHANNEL,
   LOGSTATE
) log_maincontext().iimpl->setstate(log_maincontext().object, LOGCHANNEL, LOGSTATE)

Sets LOGSTATE for LOGCHANNEL.

Parameter

LOGCHANNELThe number of the log channel - see log_channel_e.
LOGSTATEThe state of the LOGCHANNEL which will be set - see log_state_e.

log-text

PRINTF_LOG

#define PRINTF_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   ...
) do { log_maincontext().iimpl->printf( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, __VA_ARGS__ ) ; } while(0)

Logs a generic printf type format string.

Parameter

LOGCHANNELThe name of the channel where the log is written to.  See log_channel_e.
FLAGSAdditional flags to control the logging process.  See log_flags_e.
HEADERThe pointer to a struct of type log_header_t.  Could be set to 0 if no header should be printed.
FORMATThe format string as in the standard library function printf.
...Additional value parameters of the correct type as determined by the <FORMAT> parameter.

Example

int i ; PRINTF_LOG(log_channel_ERR, log_flags_NONE, 0, "%d", i)

PRINTTEXT_LOG

#define PRINTTEXT_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   TEXTID,
   ...
) do { if (0) { test for correct parameter TEXTID( (struct logbuffer_t*)0 , ## __VA_ARGS__) ; } log_maincontext().iimpl->printtext( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, & v ## TEXTID, __VA_ARGS__) ; } while(0)

Logs a text resource string.

Parameter

LOGCHANNELThe name of the channel where the log is written to.  See log_channel_e.
FLAGSAdditional flags to control the logging process.  See log_flags_e.
TEXTIDThe name of the text resource, for example FUNCTION_ABORT_ERRLOG.
HEADERThe pointer to a struct of type log_header_t.  Could be set to 0 if no header should be printed.
...Additional value parameters of the correct type as determined by the text resource.

Example

int err ; PRINTTEXT_LOG(log_channel_ERR, log_flags_NONE, 0, &vRESOURCE_NAME_ERRLOG, err)

PRINTTEXT_NOARG_LOG

#define PRINTTEXT_NOARG_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   TEXTID
) do { if (0) { test for correct parameter TEXTID( (struct logbuffer_t*)0) ; } log_maincontext().iimpl->printtext( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, & v ## TEXTID) ; } while(0)

Logs a text resource string.

Parameter

LOGCHANNELThe name of the channel where the log is written to.  See log_channel_e.
FLAGSAdditional flags to control the logging process.  See log_flags_e.
TEXTIDThe name of the text resource, for example FUNCTION_ABORT_ERRLOG.
HEADERThe pointer to a struct of type log_header_t.  Could be set to 0 if no header should be printed.

Example

int err ; PRINTTEXT_NOARG_LOG(log_channel_ERR, log_flags_NONE, 0, &vRESOURCE_NAME_ERRLOG)

log-variables

PRINTVAR_LOG

#define PRINTVAR_LOG(
   LOGCHANNEL,
   format,
   varname,
   cast
) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #varname "=%" format "\n", cast (varname))

Logs “<varname>=varvalue” of a variable with name varname.

Parameter

LOGCHANNELThe name of the channel where the log is written to.  See log_channel_e.
formatType of the variable as string in printf format.  Use “d” for signed int or “u” for unsigned int.  Use the C99 standard conforming names PRIx64 for hexadecimal output of uint64_t/int64_t ...
varnameThe name of the variable to log.
castA type cast expression like “(void*)” without enclosing “”.  Use this to adapt the type of the variable.  Leave it empty if you do not need a type cast.

Example

This code logs “memsize=1024\n”

const size_t memsize = 1024 ;
PRINTVAR_LOG(log_channel_ERR, PRIuSIZE, memsize, ) ;

PRINTARRAYFIELD_LOG

#define PRINTARRAYFIELD_LOG(
   LOGCHANNEL,
   format,
   arrname,
   index
) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #arrname "[%d]=%" format "\n", i, (arrname)[i])

Log value of variable stored in array at offset i.  The logged text is “array[i]=value”.

Parameter

LOGCHANNELThe name of the channel where the log is written to.  See log_channel_e.
formatType of the variable as string in printf format.  Use “s” for C strings.  Use the C99 standard conforming names PRIx64 for hexadecimal output of uint64_t/int64_t ...
arrnameThe name of the array.
indexThe index of the array entry whose value is to be logged.

Example

This code logs “names[0]=Jo\n” and “names[1]=Jane\n”.

const char * names[] = { "Jo", "Jane" } ;
for(int i = 0; i < 2; ++i) { PRINTARRAYFIELD_LOG(log_channel_ERR, s,names,i) ; }

PRINTCSTR_LOG

#define PRINTCSTR_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "s", varname, )

Log “name=value” of string variable.  Example:

const char * name = "Jo" ; PRINTCSTR_LOG(log_channel_ERR, name) ;

PRINTINT_LOG

#define PRINTINT_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "d", varname, )

Log “name=value” of int variable.  Example:

const int max = 100 ; PRINTINT_LOG(log_channel_ERR, max) ;

PRINTINT64_LOG

#define PRINTINT64_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRId64, varname, )

Log “name=value” of int64_t variable.  Example:

const int64_t min = -100 ; PRINTINT64_LOG(log_channel_ERR, min) ;

PRINTSIZE_LOG

#define PRINTSIZE_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIuSIZE, varname, )

Log “name=value” of size_t variable.  Example:

const size_t maxsize = 100 ; PRINTSIZE_LOG(log_channel_ERR, maxsize) ;

PRINTUINT8_LOG

#define PRINTUINT8_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu8, varname, )

Log “name=value” of uint8_t variable.  Example:

const uint8_t limit = 255 ; PRINTUINT8_LOG(log_channel_ERR, limit) ;

PRINTUINT16_LOG

#define PRINTUINT16_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu16, varname, )

Log “name=value” of uint16_t variable.  Example:

const uint16_t limit = 65535 ; PRINTUINT16_LOG(log_channel_ERR, limit) ;

PRINTUINT32_LOG

#define PRINTUINT32_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu32, varname, )

Log “name=value” of uint32_t variable.  Example:

const uint32_t max = 100 ; PRINTUINT32_LOG(log_channel_ERR, max) ;

PRINTUINT64_LOG

#define PRINTUINT64_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu64, varname, )

Log “name=value” of uint64_t variable.  Example:

const uint64_t max = 100 ; PRINTUINT64_LOG(log_channel_ERR, max) ;

PRINTPTR_LOG

#define PRINTPTR_LOG(
   LOGCHANNEL,
   varname
) PRINTVAR_LOG(LOGCHANNEL, "p", varname, (const void*))

Log “name=value” of pointer variable.  Example:

const void * ptr = &g_variable ; PRINTPTR_LOG(log_channel_ERR, ptr) ;

PRINTDOUBLE_LOG

#define PRINTDOUBLE_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "g", varname, )

Log “name=value” of double or float variable.  Example:

const double d = 1.234 ; PRINTDOUBLE_LOG(log_channel_ERR, d) ;
Write error messages to STDERR for diagnostic purposes.
Makes LogWriter service more accessible with simple defined macros.
#define GETBUFFER_LOG(
    LOGCHANNEL,
   /*out char ***/buffer,
   /*out size_t **/size
) log_maincontext().iimpl->getbuffer(log_maincontext().object, LOGCHANNEL, buffer, size)
Returns C-string of buffered log and its length.
#define COMPARE_LOG(
    LOGCHANNEL,
    /*size_t*/size,
   /*const char[size]*/logbuffer
) log_maincontext().iimpl->compare(log_maincontext().object, LOGCHANNEL, size, logbuffer)
Compare logbuffer[size] to buffered log entries.
#define GETSTATE_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->getstate(log_maincontext().object, LOGCHANNEL)
Returns log_state_e for LOGCHANNEL.
Used to configure the state of a log_channel_e.
#define CLEARBUFFER_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->clearbuffer(log_maincontext().object, LOGCHANNEL)
Clears log buffer (sets length of logbuffer to 0).
#define FLUSHBUFFER_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->flushbuffer(log_maincontext().object, LOGCHANNEL)
Writes content of internal buffer and then clears it.
#define SETSTATE_LOG(
   LOGCHANNEL,
   LOGSTATE
) log_maincontext().iimpl->setstate(log_maincontext().object, LOGCHANNEL, LOGSTATE)
Sets LOGSTATE for LOGCHANNEL.
#define PRINTF_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   ...
) do { log_maincontext().iimpl->printf( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, __VA_ARGS__ ) ; } while(0)
Logs a generic printf type format string.
#define PRINTTEXT_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   TEXTID,
   ...
) do { if (0) { test for correct parameter TEXTID( (struct logbuffer_t*)0 , ## __VA_ARGS__) ; } log_maincontext().iimpl->printtext( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, & v ## TEXTID, __VA_ARGS__) ; } while(0)
Logs a text resource string.
#define PRINTTEXT_NOARG_LOG(
   LOGCHANNEL,
   FLAGS,
   HEADER,
   TEXTID
) do { if (0) { test for correct parameter TEXTID( (struct logbuffer_t*)0) ; } log_maincontext().iimpl->printtext( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, & v ## TEXTID) ; } while(0)
Logs a text resource string.
#define PRINTVAR_LOG(
   LOGCHANNEL,
   format,
   varname,
   cast
) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #varname "=%" format "\n", cast (varname))
Logs “<varname>=varvalue” of a variable with name varname.
#define PRINTARRAYFIELD_LOG(
   LOGCHANNEL,
   format,
   arrname,
   index
) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #arrname "[%d]=%" format "\n", i, (arrname)[i])
Log value of variable stored in array at offset i.
#define PRINTCSTR_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "s", varname, )
Log “name=value” of string variable.
#define PRINTINT_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "d", varname, )
Log “name=value” of int variable.
#define PRINTINT64_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRId64, varname, )
Log “name=value” of int64_t variable.
#define PRINTSIZE_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIuSIZE, varname, )
Log “name=value” of size_t variable.
#define PRINTUINT8_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu8, varname, )
Log “name=value” of uint8_t variable.
#define PRINTUINT16_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu16, varname, )
Log “name=value” of uint16_t variable.
#define PRINTUINT32_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu32, varname, )
Log “name=value” of uint32_t variable.
#define PRINTUINT64_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, PRIu64, varname, )
Log “name=value” of uint64_t variable.
#define PRINTPTR_LOG(
   LOGCHANNEL,
   varname
) PRINTVAR_LOG(LOGCHANNEL, "p", varname, (const void*))
Log “name=value” of pointer variable.
#define PRINTDOUBLE_LOG(LOGCHANNEL,
varname) PRINTVAR_LOG(LOGCHANNEL, "g", varname, )
Log “name=value” of double or float variable.
Used to switch between log channels.
Used to configure system wide restrictions.
struct log_header_t
Contains information for a log header.
Close