ErrlogMacros

Defines error logging macros.

  • Includes text resource file which contains errorlog messages and defines TRACE_ERRLOG to log them.
  • All logging macros log to the error channel.
Summary
ErrlogMacrosDefines error logging macros.
CopyrightThis program is free software.
Files
C-kern/api/io/writer/log/errlog_macros.hHeader file of ErrlogMacros.
C-kern/io/writer/errlog.cImplementation file Errorlog-Writer.
Functions
query
GETBUFFER_ERRLOGSee GETBUFFER_LOG.
COMPARE_ERRLOGSee COMPARE_LOG.
change
CLEARBUFFER_ERRLOGSee CLEARBUFFER_LOG.
FLUSHBUFFER_LOGSee FLUSHBUFFER_LOG.
log-text
PRINTF_ERRLOGLogs a generic printf type format string as error.
PRINTTEXT_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text.
PRINTTEXT_USER_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text to log_channel_USERERR.
TRACEABORT_ERRLOGLogs the abortion of a function and the its corresponding error code.
TRACEABORTFREE_ERRLOGLogs that an error occurred during free_XXX or delete_XXX.
TRACECALL_ERRLOGLogs reason of failure and name of called app function.
TRACEOUTOFMEM_ERRLOGLogs “out of memory” reason for function abort.
TRACESYSCALL_ERRLOGLogs reason of failure and name of called system function.
TRACE_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
TRACE2_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
TRACE_NOARG_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
log-variables
PRINTARRAYFIELD_ERRLOGLog value of variable stored in array at offset i.
PRINTCSTR_ERRLOGLog “name=value” of string variable.
PRINTINT_ERRLOGLog “name=value” of int variable.
PRINTINT64_ERRLOGLog “name=value” of int variable.
PRINTSIZE_ERRLOGLog “name=value” of size_t variable.
PRINTUINT8_ERRLOGLog “name=value” of uint8_t variable.
PRINTUINT16_ERRLOGLog “name=value” of uint16_t variable.
PRINTUINT32_ERRLOGLog “name=value” of uint32_t variable.
PRINTUINT64_ERRLOGLog “name=value” of uint64_t variable.
PRINTPTR_ERRLOGLog “name=value” of pointer variable.
PRINTDOUBLE_ERRLOGLog “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/errlog_macros.h

Header file of ErrlogMacros.

C-kern/io/writer/errlog.c

Implementation file Errorlog-Writer.

Functions

Summary
query
GETBUFFER_ERRLOGSee GETBUFFER_LOG.
COMPARE_ERRLOGSee COMPARE_LOG.
change
CLEARBUFFER_ERRLOGSee CLEARBUFFER_LOG.
FLUSHBUFFER_LOGSee FLUSHBUFFER_LOG.
log-text
PRINTF_ERRLOGLogs a generic printf type format string as error.
PRINTTEXT_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text.
PRINTTEXT_USER_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text to log_channel_USERERR.
TRACEABORT_ERRLOGLogs the abortion of a function and the its corresponding error code.
TRACEABORTFREE_ERRLOGLogs that an error occurred during free_XXX or delete_XXX.
TRACECALL_ERRLOGLogs reason of failure and name of called app function.
TRACEOUTOFMEM_ERRLOGLogs “out of memory” reason for function abort.
TRACESYSCALL_ERRLOGLogs reason of failure and name of called system function.
TRACE_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
TRACE2_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
TRACE_NOARG_ERRLOGLogs an TEXTID from C-kern/resource/errlog.text and error number err.
log-variables
PRINTARRAYFIELD_ERRLOGLog value of variable stored in array at offset i.
PRINTCSTR_ERRLOGLog “name=value” of string variable.
PRINTINT_ERRLOGLog “name=value” of int variable.
PRINTINT64_ERRLOGLog “name=value” of int variable.
PRINTSIZE_ERRLOGLog “name=value” of size_t variable.
PRINTUINT8_ERRLOGLog “name=value” of uint8_t variable.
PRINTUINT16_ERRLOGLog “name=value” of uint16_t variable.
PRINTUINT32_ERRLOGLog “name=value” of uint32_t variable.
PRINTUINT64_ERRLOGLog “name=value” of uint64_t variable.
PRINTPTR_ERRLOGLog “name=value” of pointer variable.
PRINTDOUBLE_ERRLOGLog “name=value” of double or float variable.

query

GETBUFFER_ERRLOG

#define GETBUFFER_ERRLOG(buffer,
size) GETBUFFER_LOG(log_channel_ERR, buffer, size)

See GETBUFFER_LOG.

COMPARE_ERRLOG

#define COMPARE_ERRLOG(size,
logbuffer) COMPARE_LOG(log_channel_ERR, size, logbuffer)

See COMPARE_LOG.

change

CLEARBUFFER_ERRLOG

#define CLEARBUFFER_ERRLOG() CLEARBUFFER_LOG(log_channel_ERR)

See CLEARBUFFER_LOG.

FLUSHBUFFER_LOG

#define FLUSHBUFFER_ERRLOG() FLUSHBUFFER_LOG(log_channel_ERR)

See FLUSHBUFFER_LOG.

log-text

PRINTF_ERRLOG

#define PRINTF_ERRLOG(
   ...
) PRINTF_LOG(log_channel_ERR, log_flags_NONE, 0, __VA_ARGS__)

Logs a generic printf type format string as error.

Parameter

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_ERRLOG("%d", i)

PRINTTEXT_ERRLOG

#define PRINTTEXT_ERRLOG(
   TEXTID,
   ...
) do { PRINTTEXT_LOG( log_channel_ERR, log_flags_NONE, 0, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)

Logs an TEXTID from C-kern/resource/errlog.text.  The parameters after TEXTID must match the parameters of the resource TEXTID.

PRINTTEXT_USER_ERRLOG

#define PRINTTEXT_USER_ERRLOG(
   TEXTID,
   ...
) do { PRINTTEXT_LOG( log_channel_USERERR, log_flags_NONE, 0, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)

Logs an TEXTID from C-kern/resource/errlog.text to log_channel_USERERR.  The parameters after TEXTID must match the parameters of the resource TEXTID.

TRACEABORT_ERRLOG

#define TRACEABORT_ERRLOG(
   err
) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT, err)

Logs the abortion of a function and the its corresponding error code.  If a function encounters an error from which it cannot recover it should roll back the system to its previous state before it was called and use

TRACEABORT_ERRLOG(return_error_code)

to signal this fact.

TRACEABORTFREE_ERRLOG

#define TRACEABORTFREE_ERRLOG(
   err
) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT_FREE, err)

Logs that an error occurred during free_XXX or delete_XXX.  This means that not all resources could have been freed only as many as possible.

TRACECALL_ERRLOG

#define TRACECALL_ERRLOG(
   fct_name,
   err
) TRACE_ERRLOG(log_flags_START, FUNCTION_CALL, err, fct_name)

Logs reason of failure and name of called app function.  Use this function to log an error in a function which calls a library function which does no logging on its own.

TODO: Support own error IDs

TRACEOUTOFMEM_ERRLOG

#define TRACEOUTOFMEM_ERRLOG(
   size,
   err
) TRACE_ERRLOG(log_flags_START, MEMORY_OUT_OF, err, size)

Logs “out of memory” reason for function abort.  If a function could not allocate memory of size bytes and therefore aborts with an error code

TRACEOUTOFMEM_ERRLOG(size_of_memory_in_bytes)

should be called before TRACEABORT_ERRLOG to document the event leading to an abort.

TRACESYSCALL_ERRLOG

#define TRACESYSCALL_ERRLOG(
   sys_fctname,
   err
) TRACE_ERRLOG(log_flags_START, FUNCTION_SYSCALL, err, sys_fctname)

Logs reason of failure and name of called system function.  In POSIX compatible systems sys_errno should be set to the C error variable: errno.

TRACE_ERRLOG

#define TRACE_ERRLOG(
   FLAGS,
   TEXTID,
   err,
   ...
) TRACE2_ERRLOG(FLAGS, TEXTID, __FUNCTION__, __FILE__, __LINE__, err, __VA_ARGS__)

Logs an TEXTID from C-kern/resource/errlog.text and error number err.  Parameter FLAGS carries additional flags to control the logging process - see log_flags_e.  Any additional arguments are listed after err.  Use TRACE_ERRLOG to log any language specific text with additional parameter values.

TRACE2_ERRLOG

#define TRACE2_ERRLOG(
   FLAGS,
   TEXTID,
   funcname,
   filename,
   linenr,
   err,
   ...
) do { log_header_t _header = log_header_INIT(funcname, filename, linenr, err) ; PRINTTEXT_LOG(log_channel_ERR, FLAGS, &_header, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)

Logs an TEXTID from C-kern/resource/errlog.text and error number err.

Parameter

FLAGSAdditional flags to control the logging process.  See log_flags_e.
TEXTIDError text ID from C-kern/resource/errlog.text.
funcnameName of function - used to describe error position.
filenameName of source file - used to describe error position.
linenrNumber of current source line - used to describe error position.
errError number.
...The following parameter are used to parameterize TEXTID.

TRACE_NOARG_ERRLOG

#define TRACE_NOARG_ERRLOG(
   FLAGS,
   TEXTID,
   err
) do { log_header_t _header = log_header_INIT(__FUNCTION__, __FILE__, __LINE__, err) ; PRINTTEXT_NOARG_LOG( log_channel_ERR, FLAGS, &_header, TEXTID ## _ERRLOG) ; } while(0)

Logs an TEXTID from C-kern/resource/errlog.text and error number err.  Parameter FLAGS carries additional flags to control the logging process - see log_flags_e.  There are no additional arguments.  Use TRACE_NOARG_ERRLOG to log any language specific text with no parameter values.

log-variables

PRINTARRAYFIELD_ERRLOG

#define PRINTARRAYFIELD_ERRLOG(
   format,
   arrname,
   index
) PRINTARRAYFIELD_LOG(log_channel_ERR, format, arrname, index)

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

Parameter

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_ERRLOG("s", names, i) ; }

PRINTCSTR_ERRLOG

#define PRINTCSTR_ERRLOG(varname) PRINTCSTR_LOG(log_channel_ERR, varname)

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

const char * name = "Jo" ; PRINTCSTR_ERRLOG(name) ;

PRINTINT_ERRLOG

#define PRINTINT_ERRLOG(varname) PRINTINT_LOG(log_channel_ERR, varname)

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

const int max = 100 ; PRINTINT_ERRLOG(max) ;

PRINTINT64_ERRLOG

#define PRINTINT64_ERRLOG(varname) PRINTINT64_LOG(log_channel_ERR, varname)

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

const int64_t min = 100 ; PRINTINT64_ERRLOG(min) ;

PRINTSIZE_ERRLOG

#define PRINTSIZE_ERRLOG(varname) PRINTSIZE_LOG(log_channel_ERR, varname)

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

const size_t maxsize = 100 ; PRINTSIZE_ERRLOG(maxsize) ;

PRINTUINT8_ERRLOG

#define PRINTUINT8_ERRLOG(varname) PRINTUINT8_LOG(log_channel_ERR, varname)

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

const uint8_t limit = 255 ; PRINTUINT8_ERRLOG(limit) ;

PRINTUINT16_ERRLOG

#define PRINTUINT16_ERRLOG(varname) PRINTUINT16_LOG(log_channel_ERR, varname)

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

const uint16_t limit = 65535 ; PRINTUINT16_ERRLOG(limit) ;

PRINTUINT32_ERRLOG

#define PRINTUINT32_ERRLOG(varname) PRINTUINT32_LOG(log_channel_ERR, varname)

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

const uint32_t max = 100 ; PRINTUINT32_ERRLOG(max) ;

PRINTUINT64_ERRLOG

#define PRINTUINT64_ERRLOG(varname) PRINTUINT64_LOG(log_channel_ERR, varname)

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

const uint64_t max = 100 ; PRINTUINT64_ERRLOG(max) ;

PRINTPTR_ERRLOG

#define PRINTPTR_ERRLOG(varname) PRINTPTR_LOG(log_channel_ERR, varname)

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

const void * ptr = &g_variable ; PRINTPTR_ERRLOG(ptr) ;

PRINTDOUBLE_ERRLOG

#define PRINTDOUBLE_ERRLOG(varname) PRINTDOUBLE_LOG(log_channel_ERR, varname)

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

const double d = 1.234 ; PRINTDOUBLE_ERRLOG(d) ;
Defines error logging macros.
Writes error log text.
#define GETBUFFER_ERRLOG(buffer,
size) GETBUFFER_LOG(log_channel_ERR, buffer, size)
See 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.
#define COMPARE_ERRLOG(size,
logbuffer) COMPARE_LOG(log_channel_ERR, size, logbuffer)
See 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.
#define CLEARBUFFER_ERRLOG() CLEARBUFFER_LOG(log_channel_ERR)
See CLEARBUFFER_LOG.
#define CLEARBUFFER_LOG(
   LOGCHANNEL
) log_maincontext().iimpl->clearbuffer(log_maincontext().object, LOGCHANNEL)
Clears log buffer (sets length of logbuffer to 0).
#define FLUSHBUFFER_ERRLOG() FLUSHBUFFER_LOG(log_channel_ERR)
See FLUSHBUFFER_LOG.
#define PRINTF_ERRLOG(
   ...
) PRINTF_LOG(log_channel_ERR, log_flags_NONE, 0, __VA_ARGS__)
Logs a generic printf type format string as error.
#define PRINTTEXT_ERRLOG(
   TEXTID,
   ...
) do { PRINTTEXT_LOG( log_channel_ERR, log_flags_NONE, 0, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)
Logs an TEXTID from C-kern/resource/errlog.text.
#define PRINTTEXT_USER_ERRLOG(
   TEXTID,
   ...
) do { PRINTTEXT_LOG( log_channel_USERERR, log_flags_NONE, 0, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)
Logs an TEXTID from C-kern/resource/errlog.text to log_channel_USERERR.
Uses STDERR channel for log output.
#define TRACEABORT_ERRLOG(
   err
) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT, err)
Logs the abortion of a function and the its corresponding error code.
#define TRACEABORTFREE_ERRLOG(
   err
) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT_FREE, err)
Logs that an error occurred during free_XXX or delete_XXX.
#define TRACECALL_ERRLOG(
   fct_name,
   err
) TRACE_ERRLOG(log_flags_START, FUNCTION_CALL, err, fct_name)
Logs reason of failure and name of called app function.
#define TRACEOUTOFMEM_ERRLOG(
   size,
   err
) TRACE_ERRLOG(log_flags_START, MEMORY_OUT_OF, err, size)
Logs “out of memory” reason for function abort.
#define TRACESYSCALL_ERRLOG(
   sys_fctname,
   err
) TRACE_ERRLOG(log_flags_START, FUNCTION_SYSCALL, err, sys_fctname)
Logs reason of failure and name of called system function.
#define TRACE_ERRLOG(
   FLAGS,
   TEXTID,
   err,
   ...
) TRACE2_ERRLOG(FLAGS, TEXTID, __FUNCTION__, __FILE__, __LINE__, err, __VA_ARGS__)
Logs an TEXTID from C-kern/resource/errlog.text and error number err.
#define TRACE2_ERRLOG(
   FLAGS,
   TEXTID,
   funcname,
   filename,
   linenr,
   err,
   ...
) do { log_header_t _header = log_header_INIT(funcname, filename, linenr, err) ; PRINTTEXT_LOG(log_channel_ERR, FLAGS, &_header, TEXTID ## _ERRLOG, __VA_ARGS__) ; } while(0)
Logs an TEXTID from C-kern/resource/errlog.text and error number err.
#define TRACE_NOARG_ERRLOG(
   FLAGS,
   TEXTID,
   err
) do { log_header_t _header = log_header_INIT(__FUNCTION__, __FILE__, __LINE__, err) ; PRINTTEXT_NOARG_LOG( log_channel_ERR, FLAGS, &_header, TEXTID ## _ERRLOG) ; } while(0)
Logs an TEXTID from C-kern/resource/errlog.text and error number err.
#define PRINTARRAYFIELD_ERRLOG(
   format,
   arrname,
   index
) PRINTARRAYFIELD_LOG(log_channel_ERR, format, arrname, index)
Log value of variable stored in array at offset i.
#define PRINTCSTR_ERRLOG(varname) PRINTCSTR_LOG(log_channel_ERR, varname)
Log “name=value” of string variable.
#define PRINTINT_ERRLOG(varname) PRINTINT_LOG(log_channel_ERR, varname)
Log “name=value” of int variable.
#define PRINTINT64_ERRLOG(varname) PRINTINT64_LOG(log_channel_ERR, varname)
Log “name=value” of int variable.
#define PRINTSIZE_ERRLOG(varname) PRINTSIZE_LOG(log_channel_ERR, varname)
Log “name=value” of size_t variable.
#define PRINTUINT8_ERRLOG(varname) PRINTUINT8_LOG(log_channel_ERR, varname)
Log “name=value” of uint8_t variable.
#define PRINTUINT16_ERRLOG(varname) PRINTUINT16_LOG(log_channel_ERR, varname)
Log “name=value” of uint16_t variable.
#define PRINTUINT32_ERRLOG(varname) PRINTUINT32_LOG(log_channel_ERR, varname)
Log “name=value” of uint32_t variable.
#define PRINTUINT64_ERRLOG(varname) PRINTUINT64_LOG(log_channel_ERR, varname)
Log “name=value” of uint64_t variable.
#define PRINTPTR_ERRLOG(varname) PRINTPTR_LOG(log_channel_ERR, varname)
Log “name=value” of pointer variable.
#define PRINTDOUBLE_ERRLOG(varname) PRINTDOUBLE_LOG(log_channel_ERR, varname)
Log “name=value” of double or float variable.
Used to configure system wide restrictions.
Close