Interface to access log service. An interface is a structure which lists function pointers. These function pointers point to functions exported by a service implementation. Used in LogWriter and LogMain.
Log-Object | Interface to access log service. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Log-Object. |
Types | |
struct log_t | Export log_t. |
struct log_it | Export interface log_it. |
struct log_header_t | Export log_header_t. |
log_text_f | Declare function pointer which writes a text resource into logbuffer_t. |
Enumerations | |
log_config_e | Used to configure system wide restrictions. |
log_flags_e | Used to configure system wide restrictions. |
log_channel_e | Used to switch between log channels. |
log_state_e | Used to configure the state of a log_channel_e. |
log_t | Uses iobj_DECLARE to declare object supporting interface log_it. |
generic | |
genericcast_log | Casts parameter iobj to pointer to log_t. |
log_it | The function table which describes the log service. |
printf | Writes a new log entry to in internal buffer. |
printtext | Writes text resource as new log entry to in internal buffer. |
flushbuffer | Writes content of buffer to configured file descriptor and clears log buffer. |
clearbuffer | Clears log buffer (sets length of logbuffer to 0). |
getbuffer | Returns content of log buffer as C-string and its size in bytes. |
getstate | Returns configured log_state_e for a specific log_channel_e channel. |
comapre | Returns 0 if logbuffer compares equal to content in log for a specific log_channel_e channel. |
setstate | Sets log_state_e logstate for a specific log_channel_e channel. |
generic | |
genericcast_logit | Casts pointer logif into pointer to interface log_it. |
log_it_DECLARE | Declares a function table for accessing a log service. |
log_header_t | Contains information for a log header. |
lifetime | |
inline implementation | |
log_t | |
genericcast_log | Implements log_t.genericcast_log. |
log_it | |
genericcast_logit | Implements log_it.genericcast_logit. |
log_it_DECLARE | Implements log_it.log_it_DECLARE. |
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 Log-Object.
typedef struct log_t log_t
Export log_t. Interfaceable log object.
typedef struct log_it log_it
Export interface log_it. See log_it_DECLARE for a description of the functional interface.
typedef struct log_header_t log_header_t
Export log_header_t.
typedef void ( * log_text_f )(struct logbuffer_t * logbuffer, va_list vargs)
Declare function pointer which writes a text resource into logbuffer_t.
Used to configure system wide restrictions.
log_flags_NONE | Indicates that the log entry does not change append or not append state. If the last call to print contained log_flags_START the new entry is appended. If the last call to print contained log_flags_END the new entry is not appended. |
log_flags_START | Indicates that this is the beginning of a new log entry. This flag implicitly ends the previous log entry if not done explicitly. The log entry is therefore not appended to a previous one. Every following log output is now appended to a memory buffer and truncated if necessary until another call to print is done with flag set to log_flags_END or log_flags_START. |
log_flags_END | Indicates that this is the last part of a log entry. You can set log_flags_START and log_flags_END at the same time to indicate that the printed log entry should not be appended to a previous one and the following entries should not be appended to this one. |
log_flags_OPTIONALHEADER | A given log_header_t is only written before the log entry if the pointer to the function name in log_header_t differs from the pointer given in the previous call. The flag log_flags_END sets the remembered pointer to the function name to 0. Set this flag on the last part of the log entry if another header could be written in the same function with flag log_flags_START. Both log macros TRACEABORT_ERRLOG and TRACEABORTFREE_ERRLOG set this flag. They do not know if another call to TRACESYSCALL_ERRLOG already printed a header. |
Used to switch between log channels.
Used to configure the state of a log_channel_e.
iobj_DECLARE( log_t, log )
Uses iobj_DECLARE to declare object supporting interface log_it.
generic | |
genericcast_log | Casts parameter iobj to pointer to log_t. |
log_t * genericcast_log( void * iobj )
Casts parameter iobj to pointer to log_t. iobj must be a pointer to an anonymous interfaceable log object.
struct log_it
The function table which describes the log service.
printf | Writes a new log entry to in internal buffer. |
printtext | Writes text resource as new log entry to in internal buffer. |
flushbuffer | Writes content of buffer to configured file descriptor and clears log buffer. |
clearbuffer | Clears log buffer (sets length of logbuffer to 0). |
getbuffer | Returns content of log buffer as C-string and its size in bytes. |
getstate | Returns configured log_state_e for a specific log_channel_e channel. |
comapre | Returns 0 if logbuffer compares equal to content in log for a specific log_channel_e channel. |
setstate | Sets log_state_e logstate for a specific log_channel_e channel. |
generic | |
genericcast_logit | Casts pointer logif into pointer to interface log_it. |
log_it_DECLARE | Declares a function table for accessing a log service. |
void ( * printf ) (void * log, uint8_t channel, uint8_t flags, const log_header_t * header, const char * format, ... ) __attribute__ ((__format__ (__printf__, 5, 6)))
Writes a new log entry to in internal buffer. Parameter channel must be set to a value from log_channel_e. If header is not 0 a header is written which contains “[thread id, timestamp]\nfuncname() file:linenr\n, Error NR - DESCRIPTION\n”. If the entry is bigger than log_config_MINSIZE it may be truncated if internal buffer size is lower. See logwriter_t.printf_logwriter for an implementation.
void ( * printtext ) (void * log, uint8_t channel, uint8_t flags, const log_header_t * header, log_text_f textf, ... )
Writes text resource as new log entry to in internal buffer. See printf for a description of the parameter. The variable parameter list must match the resource.
void ( * flushbuffer ) (void * log, uint8_t channel)
Writes content of buffer to configured file descriptor and clears log buffer. This call is ignored if buffer is empty or log is not configured to be in buffered mode. See logwriter_t.flushbuffer_logwriter for an implementation.
void ( * clearbuffer ) (void * log, uint8_t channel)
Clears log buffer (sets length of logbuffer to 0). This call is ignored if the log is not configured to be in buffered mode. See logwriter_t.clearbuffer_logwriter for an implementation.
void ( * getbuffer ) (const void * log, uint8_t channel, /*out*/uint8_t ** buffer, /*out*/size_t * size)
Returns content of log buffer as C-string and its size in bytes. The returned values are valid as long as no other function is called on log. The string has a trailing NULL byte, i.e. buffer[size] == 0. See logwriter_t.getbuffer_logwriter for an implementation.
uint8_t ( * getstate ) (const void * log, uint8_t channel)
Returns configured log_state_e for a specific log_channel_e channel. You can switch log_state_e by calling setstate.
Returns 0 if logbuffer compares equal to content in log for a specific log_channel_e channel. The return value EINVAL indicates not equal. The comparison should ignore timestamps.
void ( * setstate ) (void * log, uint8_t channel, uint8_t logstate)
Sets log_state_e logstate for a specific log_channel_e channel. You can query the current log_state_e by calling getstate.
log_it * genericcast_logit( void * logif, TYPENAME log_t )
Casts pointer logif into pointer to interface log_it. Parameter logif must point to a type declared with log_it_DECLARE. The other parameters must be the same as in log_it_DECLARE without the first.
void log_it_DECLARE( TYPENAME declared_it, TYPENAME log_t )
Declares a function table for accessing a log service. The declared interface is structural compatible with log_it. The difference between the newly declared interface and the generic interface is the type of the first parameter.
See log_it for a list of declared functions.
declared_it | The name of the structure which is declared as the interface. The name should have the suffix “_it”. |
log_t | The type of the log object which is the first parameter of all interface functions. |
log_t | |
genericcast_log | Implements log_t.genericcast_log. |
log_it | |
genericcast_logit | Implements log_it.genericcast_logit. |
log_it_DECLARE | Implements log_it.log_it_DECLARE. |
#define genericcast_log( iobj ) genericcast_iobj(iobj, log)
Implements log_t.genericcast_log.
#define genericcast_logit( logif, log_t ) ( __extension__ ({ static_assert( &((typeof(logif))0)->printf == (void(**)(log_t*,uint8_t,uint8_t, const log_header_t*, const char*,...)) &((log_it*)0)->printf && &((typeof(logif))0)->printtext == (void(**)(log_t*,uint8_t,uint8_t, const log_header_t*, log_text_f,...)) &((log_it*)0)->printtext && &((typeof(logif))0)->flushbuffer == (void(**)(log_t*,uint8_t)) &((log_it*)0)->flushbuffer && &((typeof(logif))0)->clearbuffer == (void(**)(log_t*,uint8_t)) &((log_it*)0)->clearbuffer && &((typeof(logif))0)->getbuffer == (void(**)(const log_t*,uint8_t, uint8_t**,size_t*)) &((log_it*)0)->getbuffer && &((typeof(logif))0)->getstate == (uint8_t(**)(const log_t*, uint8_t)) &((log_it*)0)->getstate && &((typeof(logif))0)->compare == (int(**)(const log_t*, uint8_t, size_t,const uint8_t*)) &((log_it*)0)->compare && &((typeof(logif))0)->setstate == (void(**)(log_t*,uint8_t, uint8_t)) &((log_it*)0)->setstate, "ensure same structure"); (log_it*) (logif); }))
Implements log_it.genericcast_logit.
Implements log_it.log_it_DECLARE.
Export log_t.
typedef struct log_t log_t
Uses iobj_DECLARE to declare object supporting interface log_it.
iobj_DECLARE( log_t, log )
Export interface log_it.
typedef struct log_it log_it
The function table which describes the log service.
struct log_it
Export log_header_t.
typedef struct log_header_t log_header_t
Contains information for a log header.
struct log_header_t
Declare function pointer which writes a text resource into logbuffer_t.
typedef void ( * log_text_f )(struct logbuffer_t * logbuffer, va_list vargs)
Implements iobj_t.iobj_DECLARE.
#define iobj_DECLARE( declared_t, typenameprefix ) struct declared_t { struct typenameprefix##_t * object ; struct typenameprefix##_it * iimpl ; }
Casts parameter iobj to pointer to log_t.
log_t * genericcast_log( void * iobj )
Writes a new log entry to in internal buffer.
void ( * printf ) (void * log, uint8_t channel, uint8_t flags, const log_header_t * header, const char * format, ... ) __attribute__ ((__format__ (__printf__, 5, 6)))
Writes text resource as new log entry to in internal buffer.
void ( * printtext ) (void * log, uint8_t channel, uint8_t flags, const log_header_t * header, log_text_f textf, ... )
Writes content of buffer to configured file descriptor and clears log buffer.
void ( * flushbuffer ) (void * log, uint8_t channel)
Clears log buffer (sets length of logbuffer to 0).
void ( * clearbuffer ) (void * log, uint8_t channel)
Returns content of log buffer as C-string and its size in bytes.
void ( * getbuffer ) (const void * log, uint8_t channel, /*out*/uint8_t ** buffer, /*out*/size_t * size)
Returns configured log_state_e for a specific log_channel_e channel.
uint8_t ( * getstate ) (const void * log, uint8_t channel)
Sets log_state_e logstate for a specific log_channel_e channel.
void ( * setstate ) (void * log, uint8_t channel, uint8_t logstate)
Casts pointer logif into pointer to interface log_it.
log_it * genericcast_logit( void * logif, TYPENAME log_t )
Declares a function table for accessing a log service.
void log_it_DECLARE( TYPENAME declared_it, TYPENAME log_t )
Implements log_t.genericcast_log.
#define genericcast_log( iobj ) genericcast_iobj(iobj, log)
Implements log_it.genericcast_logit.
#define genericcast_logit( logif, log_t ) ( __extension__ ({ static_assert( &((typeof(logif))0)->printf == (void(**)(log_t*,uint8_t,uint8_t, const log_header_t*, const char*,...)) &((log_it*)0)->printf && &((typeof(logif))0)->printtext == (void(**)(log_t*,uint8_t,uint8_t, const log_header_t*, log_text_f,...)) &((log_it*)0)->printtext && &((typeof(logif))0)->flushbuffer == (void(**)(log_t*,uint8_t)) &((log_it*)0)->flushbuffer && &((typeof(logif))0)->clearbuffer == (void(**)(log_t*,uint8_t)) &((log_it*)0)->clearbuffer && &((typeof(logif))0)->getbuffer == (void(**)(const log_t*,uint8_t, uint8_t**,size_t*)) &((log_it*)0)->getbuffer && &((typeof(logif))0)->getstate == (uint8_t(**)(const log_t*, uint8_t)) &((log_it*)0)->getstate && &((typeof(logif))0)->compare == (int(**)(const log_t*, uint8_t, size_t,const uint8_t*)) &((log_it*)0)->compare && &((typeof(logif))0)->setstate == (void(**)(log_t*,uint8_t, uint8_t)) &((log_it*)0)->setstate, "ensure same structure"); (log_it*) (logif); }))
Logs the abortion of a function and the its corresponding error code.
#define TRACEABORT_ERRLOG( err ) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT, err)
Logs that an error occurred during free_XXX or delete_XXX.
#define TRACEABORTFREE_ERRLOG( err ) TRACE_NOARG_ERRLOG(log_flags_END|log_flags_OPTIONALHEADER, FUNCTION_ABORT_FREE, err)
Logs reason of failure and name of called system function.
#define TRACESYSCALL_ERRLOG( sys_fctname, err ) TRACE_ERRLOG(log_flags_START, FUNCTION_SYSCALL, err, sys_fctname)
Writes new log entry to internal buffer.
void printf_logwriter( logwriter_t * lgwrt, uint8_t channel, uint8_t flags, const struct log_header_t * header, const char * format, ... ) __attribute__ ((__format__ (__printf__, 5, 6)))
Writes content of buffer to STDERR or configured file descriptor and clears log buffer.
void flushbuffer_logwriter( logwriter_t * lgwrt, uint8_t channel )
Clears log buffer (sets length of logbuffer to 0).
void clearbuffer_logwriter( logwriter_t * lgwrt, uint8_t channel )
Returns content of internal buffer corrseponding to channel as C-string.
void getbuffer_logwriter( const logwriter_t * lgwrt, uint8_t channel, /*out*/uint8_t ** buffer, /*out*/size_t * size )