forked from minhngoc25a/freetype2
[base] Added a public API to change the log handling function at run-time.
* include/freetype/ftlogging.h (FT_Custom_Log_Handler): New function pointer to store the custom callback logging function. (FT_Set_Log_Handler, FT_Set_Default_Log_Handler): New functions to set and reset custom log handler. * include/freetype/internal/ftdebug.h: Added variables to support custom callback logging function. (FT_Callback): A function to print log using custom callback logging function, which is set using `FT_Set_Log_Handler'. * src/base/ftdebug.c: Added support for handling custom logging callback function. (FT_Set_Log_Handler, FT_Set_Default_Log_Handler, FT_Callback): Added function definitions.
This commit is contained in:
parent
1c095f8174
commit
802176853b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue