Makes LogWriter service more accessible with simple defined macros.
LogMacros | Makes LogWriter service more accessible with simple defined macros. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of LogMacros. |
Functions | |
query | |
GETBUFFER_LOG | Returns C-string of buffered log and its length. |
COMPARE_LOG | Compare logbuffer[size] to buffered log entries. |
GETSTATE_LOG | Returns log_state_e for LOGCHANNEL. |
change | |
CLEARBUFFER_LOG | Clears log buffer (sets length of logbuffer to 0). |
FLUSHBUFFER_LOG | Writes content of internal buffer and then clears it. |
SETSTATE_LOG | Sets LOGSTATE for LOGCHANNEL. |
log-text | |
PRINTF_LOG | Logs a generic printf type format string. |
PRINTTEXT_LOG | Logs a text resource string. |
PRINTTEXT_NOARG_LOG | Logs a text resource string. |
log-variables | |
PRINTVAR_LOG | Logs “<varname>=varvalue” of a variable with name varname. |
PRINTARRAYFIELD_LOG | Log value of variable stored in array at offset i. |
PRINTCSTR_LOG | Log “name=value” of string variable. |
PRINTINT_LOG | Log “name=value” of int variable. |
PRINTINT64_LOG | Log “name=value” of int64_t variable. |
PRINTSIZE_LOG | Log “name=value” of size_t variable. |
PRINTUINT8_LOG | Log “name=value” of uint8_t variable. |
PRINTUINT16_LOG | Log “name=value” of uint16_t variable. |
PRINTUINT32_LOG | Log “name=value” of uint32_t variable. |
PRINTUINT64_LOG | Log “name=value” of uint64_t variable. |
PRINTPTR_LOG | Log “name=value” of pointer variable. |
PRINTDOUBLE_LOG | Log “name=value” of double or float variable. |
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.
© 2011 Jörg Seebohn
Header file of LogMacros.
query | |
GETBUFFER_LOG | Returns C-string of buffered log and its length. |
COMPARE_LOG | Compare logbuffer[size] to buffered log entries. |
GETSTATE_LOG | Returns log_state_e for LOGCHANNEL. |
change | |
CLEARBUFFER_LOG | Clears log buffer (sets length of logbuffer to 0). |
FLUSHBUFFER_LOG | Writes content of internal buffer and then clears it. |
SETSTATE_LOG | Sets LOGSTATE for LOGCHANNEL. |
log-text | |
PRINTF_LOG | Logs a generic printf type format string. |
PRINTTEXT_LOG | Logs a text resource string. |
PRINTTEXT_NOARG_LOG | Logs a text resource string. |
log-variables | |
PRINTVAR_LOG | Logs “<varname>=varvalue” of a variable with name varname. |
PRINTARRAYFIELD_LOG | Log value of variable stored in array at offset i. |
PRINTCSTR_LOG | Log “name=value” of string variable. |
PRINTINT_LOG | Log “name=value” of int variable. |
PRINTINT64_LOG | Log “name=value” of int64_t variable. |
PRINTSIZE_LOG | Log “name=value” of size_t variable. |
PRINTUINT8_LOG | Log “name=value” of uint8_t variable. |
PRINTUINT16_LOG | Log “name=value” of uint16_t variable. |
PRINTUINT32_LOG | Log “name=value” of uint32_t variable. |
PRINTUINT64_LOG | Log “name=value” of uint64_t variable. |
PRINTPTR_LOG | Log “name=value” of pointer variable. |
PRINTDOUBLE_LOG | Log “name=value” of double or float variable. |
#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>.
LOGCHANNEL | The number of the log channel - see log_channel_e. |
buffer | Contains pointer to C string after return. Must have type (char**). The string is terminated with a 0 byte. |
size | Contains size of of C string after return. The does does not include the 0 byte. |
#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>.
LOGCHANNEL | The number of the log channel - see log_channel_e. |
logsize | Contains size of logbuffer. |
buffer | Contains pointer to the logbuffer in memory which is compared to the internal buffer. |
#define GETSTATE_LOG( LOGCHANNEL ) log_maincontext().iimpl->getstate(log_maincontext().object, LOGCHANNEL)
Returns log_state_e for LOGCHANNEL.
LOGCHANNEL | The number of the log channel - see log_channel_e. |
#define SETSTATE_LOG( LOGCHANNEL, LOGSTATE ) log_maincontext().iimpl->setstate(log_maincontext().object, LOGCHANNEL, LOGSTATE)
Sets LOGSTATE for LOGCHANNEL.
LOGCHANNEL | The number of the log channel - see log_channel_e. |
LOGSTATE | The state of the LOGCHANNEL which will be set - see log_state_e. |
#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.
LOGCHANNEL | The name of the channel where the log is written to. See log_channel_e. |
FLAGS | Additional flags to control the logging process. See log_flags_e. |
HEADER | The pointer to a struct of type log_header_t. Could be set to 0 if no header should be printed. |
FORMAT | The format string as in the standard library function printf. |
... | Additional value parameters of the correct type as determined by the <FORMAT> parameter. |
int i ; PRINTF_LOG(log_channel_ERR, log_flags_NONE, 0, "%d", i)
#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.
LOGCHANNEL | The name of the channel where the log is written to. See log_channel_e. |
FLAGS | Additional flags to control the logging process. See log_flags_e. |
TEXTID | The name of the text resource, for example FUNCTION_ABORT_ERRLOG. |
HEADER | The 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. |
int err ; PRINTTEXT_LOG(log_channel_ERR, log_flags_NONE, 0, &vRESOURCE_NAME_ERRLOG, err)
#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.
LOGCHANNEL | The name of the channel where the log is written to. See log_channel_e. |
FLAGS | Additional flags to control the logging process. See log_flags_e. |
TEXTID | The name of the text resource, for example FUNCTION_ABORT_ERRLOG. |
HEADER | The pointer to a struct of type log_header_t. Could be set to 0 if no header should be printed. |
int err ; PRINTTEXT_NOARG_LOG(log_channel_ERR, log_flags_NONE, 0, &vRESOURCE_NAME_ERRLOG)
#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.
LOGCHANNEL | The name of the channel where the log is written to. See log_channel_e. |
format | Type 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 ... |
varname | The name of the variable to log. |
cast | A 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. |
This code logs “memsize=1024\n”
const size_t memsize = 1024 ; PRINTVAR_LOG(log_channel_ERR, PRIuSIZE, memsize, ) ;
#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”.
LOGCHANNEL | The name of the channel where the log is written to. See log_channel_e. |
format | Type 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 ... |
arrname | The name of the array. |
index | The index of the array entry whose value is to be logged. |
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) ; }
Returns C-string of buffered log and its length.
#define GETBUFFER_LOG( LOGCHANNEL, /*out char ** */buffer, /*out size_t * */size ) log_maincontext().iimpl->getbuffer(log_maincontext().object, LOGCHANNEL, buffer, size)
Compare logbuffer[size] to buffered log entries.
#define COMPARE_LOG( LOGCHANNEL, /*size_t*/size, /*const char[size]*/logbuffer ) log_maincontext().iimpl->compare(log_maincontext().object, LOGCHANNEL, size, logbuffer)
Returns log_state_e for LOGCHANNEL.
#define GETSTATE_LOG( LOGCHANNEL ) log_maincontext().iimpl->getstate(log_maincontext().object, LOGCHANNEL)
Clears log buffer (sets length of logbuffer to 0).
#define CLEARBUFFER_LOG( LOGCHANNEL ) log_maincontext().iimpl->clearbuffer(log_maincontext().object, LOGCHANNEL)
Writes content of internal buffer and then clears it.
#define FLUSHBUFFER_LOG( LOGCHANNEL ) log_maincontext().iimpl->flushbuffer(log_maincontext().object, LOGCHANNEL)
Sets LOGSTATE for LOGCHANNEL.
#define SETSTATE_LOG( LOGCHANNEL, LOGSTATE ) log_maincontext().iimpl->setstate(log_maincontext().object, LOGCHANNEL, LOGSTATE)
Logs a generic printf type format string.
#define PRINTF_LOG( LOGCHANNEL, FLAGS, HEADER, ... ) do { log_maincontext().iimpl->printf( log_maincontext().object, LOGCHANNEL, FLAGS, HEADER, __VA_ARGS__ ) ; } while(0)
Logs a text resource 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 “<varname>=varvalue” of a variable with name varname.
#define PRINTVAR_LOG( LOGCHANNEL, format, varname, cast ) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #varname "=%" format "\n", cast (varname))
Log value of variable stored in array at offset i.
#define PRINTARRAYFIELD_LOG( LOGCHANNEL, format, arrname, index ) PRINTF_LOG(LOGCHANNEL, log_flags_NONE, 0, #arrname "[%d]=%" format "\n", i, (arrname)[i])
Log “name=value” of string variable.
#define PRINTCSTR_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, "s", varname, )
Log “name=value” of int variable.
#define PRINTINT_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, "d", varname, )
Log “name=value” of int64_t variable.
#define PRINTINT64_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRId64, varname, )
Log “name=value” of size_t variable.
#define PRINTSIZE_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRIuSIZE, varname, )
Log “name=value” of uint8_t variable.
#define PRINTUINT8_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRIu8, varname, )
Log “name=value” of uint16_t variable.
#define PRINTUINT16_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRIu16, varname, )
Log “name=value” of uint32_t variable.
#define PRINTUINT32_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRIu32, varname, )
Log “name=value” of uint64_t variable.
#define PRINTUINT64_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, PRIu64, varname, )
Log “name=value” of pointer variable.
#define PRINTPTR_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, "p", varname, (const void*))
Log “name=value” of double or float variable.
#define PRINTDOUBLE_LOG( LOGCHANNEL, varname ) PRINTVAR_LOG(LOGCHANNEL, "g", varname, )
Contains information for a log header.
struct log_header_t