Commit 4f079511 authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Added ability to register another log function; thanks to Zack for the code

parent 2a88cf62
......@@ -154,6 +154,37 @@ extern pthread_key_t fd_log_thname;
*/
char * fd_log_time ( struct timespec * ts, char * buf, size_t len );
/*
* FUNCTION: fd_log_handler_register
* MACRO:
*
* PARAMETERS:
* fstr : Stream where the text will be sent (default: stdout)
* format : Same format string as in the printf function
* va_list : Argument list
*
* DESCRIPTION:
* Register an external method for logging purposes.
*
* RETURN VALUE:
* int : Success or failure
*/
int fd_log_handler_register ( void (*logger)(const char * format, va_list *args) );
/*
* FUNCTION: fd_log_handler_unregister
* MACRO:
*
* PARAMETERS:
*
* DESCRIPTION:
* Unregister the external logging function.
*
* RETURN VALUE:
* int : Success or failure
*/
int fd_log_handler_unregister ( void );
/*============================================================*/
/* DEBUG MACROS */
......
......@@ -49,6 +49,32 @@ char * fd_debug_one_file = NULL;
int fd_breaks = 0;
int fd_breakhere(void) { return ++fd_breaks; }
/* Allow passing of the log and debug information from base stack to extensions */
void (*fd_external_logger)( const char * format, va_list *args ) = NULL;
/* Register an dexternal call back for tracing and debug */
int fd_log_handler_register( void (*logger)(const char * format, va_list *args))
{
CHECK_PARAMS( logger );
if ( fd_external_logger != NULL )
{
return EALREADY; /* only one registeration allowed */
}
else
{
fd_external_logger = logger;
}
return 0;
}
/* Implement a simple reset function here */
int fd_log_handler_unregister ( void )
{
fd_external_logger = NULL;
return 0; /* Successfull in all cases. */
}
static void fd_cleanup_mutex_silent( void * mutex )
{
(void)pthread_mutex_unlock((pthread_mutex_t *)mutex);
......@@ -64,9 +90,16 @@ void fd_log_debug_fstr ( FILE * fstr, const char * format, ... )
pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
va_start(ap, format);
vfprintf( fstr ?: stdout, format, ap);
if ( fd_external_logger != NULL )
{
fd_external_logger( format, &ap );
}
else
{
vfprintf( fstr ?: stdout, format, ap);
fflush(fstr ?: stdout);
}
va_end(ap);
fflush(fstr ?: stdout);
pthread_cleanup_pop(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment