diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h index eae6efcd9..ba6167900 100644 --- a/include/freetype/ftlogging.h +++ b/include/freetype/ftlogging.h @@ -82,6 +82,66 @@ FT_BEGIN_HEADER FT_EXPORT( void ) FT_Trace_Set_Default_Level( void ); + /************************************************************************** + * + * @functype: + * FT_Custom_Log_Handler + * + * @description: + * Function which is used to handle the logging of tracing and debug messages + * on a file system. + * + * @input: + * ft_component :: + * The name of `FT_COMPONENT' from which the current debug or error + * message is produced. + * + * fmt :: + * Actual debug or tracing message. + * + * args:: + * Arguments of debug or tracing messages. + * + */ + typedef void + (*FT_Custom_Log_Handler)( const char* ft_component, + const char* fmt, + va_list args ); + + + /************************************************************************** + * + * @function: + * FT_Set_Log_Handler + * + * @description: + * A function to set a custom log handler + * + * @input: + * + * handler :: + * New logging function + * + */ + FT_EXPORT( void ) + FT_Set_Log_Handler( FT_Custom_Log_Handler handler ); + + + /************************************************************************** + * + * @function: + * FT_Set_Default_Log_Handler + * + * @description: + * If previously, `FT_Set_Log_Handler' functions is used to set new + * custom logging function, this API could be used to reset the back + * the log handler to FreeType's inbuilt log handler. + * + */ + + FT_EXPORT( void ) + FT_Set_Default_Log_Handler( void ); + /* */ FT_END_HEADER diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h index ff93afef7..d09401abf 100644 --- a/include/freetype/internal/ftdebug.h +++ b/include/freetype/internal/ftdebug.h @@ -126,7 +126,12 @@ FT_BEGIN_HEADER const char* dlg_tag = FT_LOGGING_TAG( FT_COMPONENT ); \ ft_add_tag( dlg_tag ); \ if( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \ + { \ + if( custom_output_handler != NULL ) \ + FT_Callback varformat; \ + else \ dlg_trace varformat; \ + } \ ft_remove_tag( dlg_tag ); \ }while( 0 ) @@ -381,9 +386,13 @@ FT_BEGIN_HEADER * 1. ft_default_log_handler: stores the function pointer which is used * internally by FreeType to print logs to file. * + * 2. custom_output_handler: stores the function pointer to the callback + * function provided by user. + * * These are defined in ftdebug.c */ extern dlg_handler ft_default_log_handler; + extern FT_Custom_Log_Handler custom_output_handler; /************************************************************************** * @@ -411,6 +420,15 @@ FT_BEGIN_HEADER FT_BASE( void ) ft_remove_tag( const char* tag ); + /************************************************************************** + * + * + * + */ + FT_BASE( void ) + FT_Callback( const char* fmt, + ... ); + #endif /* FT_LOGGING */ FT_END_HEADER diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c index 0a0b4e530..296c5bb9c 100644 --- a/src/base/ftdebug.c +++ b/src/base/ftdebug.c @@ -81,7 +81,10 @@ static bool ft_have_newline_char = true; static const char* ft_custom_trace_level = NULL; +/* declared in ftdebug.h */ + dlg_handler ft_default_log_handler = NULL; + FT_Custom_Log_Handler custom_output_handler = NULL; #endif @@ -496,6 +499,33 @@ else ft_debug_init(); } +/**************************************************************************** + * + * Functions to handle custom log handler: + * + */ + + FT_EXPORT_DEF( void ) + FT_Set_Log_Handler( FT_Custom_Log_Handler handler ) + { + custom_output_handler = handler; + } + + FT_EXPORT_DEF( void ) + FT_Set_Default_Log_Handler() + { + custom_output_handler = NULL; + } + + FT_BASE_DEF( void ) + FT_Callback( const char* fmt, ... ) + { + va_list ap; + va_start( ap, fmt ); + custom_output_handler( ft_component , fmt, ap ); + va_end( ap ); + } + #endif /* FT_LOGGING */ /* END */