summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyeshkkumar <priyeshkkumar@gmail.com>2020-08-27 13:01:05 +0530
committerPriyeshkkumar <priyeshkkumar@gmail.com>2020-08-27 13:01:05 +0530
commit802176853b5418d34704f1705617333145410625 (patch)
treecc0882247bd934ceb8f9c0a74aa18e56a6e00c66
parent1c095f81745a0c45bf5cd39702ceb9a067b55ac7 (diff)
downloadfreetype2-802176853b5418d34704f1705617333145410625.tar.gz
[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.
-rw-r--r--include/freetype/ftlogging.h60
-rw-r--r--include/freetype/internal/ftdebug.h18
-rw-r--r--src/base/ftdebug.c30
3 files changed, 108 insertions, 0 deletions
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 */