[Developers] Prototypes and Implementations: New API CCTK_Log
Jian Tao
jtao at cct.lsu.edu
Tue Jun 7 10:26:10 CDT 2005
Hi,
No matter how useful it will be, here comes CCTK_Log. ;)
Jian
[Intro]
Following the discussion about CCTK_Announce proposed by Eric last week, Tom
suggested a new CCTK_Log. I am trying to implement this API in the same way
as cctk_Info and cctk_Warn. A sample thorn called SimpleLog can be found at
cvs.cct.lsu.edu:/Frameworks/Arrangements/CCTDevelopment/SimpleLog
[Prototypes]
#define CCTK_DECLARE_LOG_CALLBACK_ARGS \
int level, \
const char *tag, \
const char *message, \
void *data
#define CCTKi_DECLARE_LOG_CALLBACKSCALL_ARGS \
int level, \
const char *tag, \
const char *message
/* prototype for log routines */
int CCTK_Log (CCTKi_DECLARE_LOG_CALLBACKSCALL_ARGS);
int CCTK_LogCallbackRegister (void *data,
void callback(CCTK_DECLARE_LOG_CALLBACK_ARGS));
[Implementation]
The default action of CCTK_Log is to dump the input to stderr. Callbacks
specified by users will be executed one by one if any. The default
format of the output is to be discussed/determined. Users can specify their
own output format freely in their own implementations as shown in
the sample thorn SimpleLog.
/********************************************************************
******************** Internal Typedefs ************************
********************************************************************/
/* structure holding a callback function pointer together with other
* information to warn/info*/
typedef struct logcallback
{
struct logcallback *next;
void (*function)(CCTK_DECLARE_LOG_CALLBACK_ARGS);
void *data;
} t_logcallback;
/********************************************************************
******************** Internal Functions ************************
********************************************************************/
void CCTKi_LogCallbacksCall (CCTKi_DECLARE_LOG_CALLBACKSCALL_ARGS)
{
t_logcallback *current;
for(current=logcallbacks; current; current=current->next)
{
current->function(CCTKi_LOG_CALLBACKSCALL_ARGS,
current->data);
}
return;
}
/********************************************************************
********************** CCTK_Log **************************
The format of the output string is to be discussed/determined
********************************************************************/
int CCTK_Log (CCTKi_DECLARE_LOG_CALLBACKSCALL_ARGS)
{
/* output Log to stderr */
fprintf (stderr, "SYSLOG[L%d] (TAG:%s): %s\n",
CCTKi_LOG_CALLBACKSCALL_ARGS);
/* call the callback function */
CCTKi_LogCallbacksCall (CCTKi_LOG_CALLBACKSCALL_ARGS);
}
More information about the Developers
mailing list