[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] priyesh_LogLibrary b378812: Updates on dynamic change of tra
From: |
Priyesh Kumar |
Subject: |
[freetype2] priyesh_LogLibrary b378812: Updates on dynamic change of trace level |
Date: |
Fri, 3 Jul 2020 05:30:39 -0400 (EDT) |
branch: priyesh_LogLibrary
commit b378812f2209b22354aea3b7de074c8a59b45945
Author: Priyeshkkumar <priyeshkkumar@gmail.com>
Commit: Priyeshkkumar <priyeshkkumar@gmail.com>
Updates on dynamic change of trace level
---
[priyesh]ChangeLog | 18 ++++++++++
include/freetype/ftlogging.h | 17 ++++++++--
include/freetype/internal/ftdebug.h | 58 ++++++++++++++++++++++----------
src/base/ftdebug.c | 66 +++++++++++++++++++++++--------------
src/base/ftobjs.c | 2 +-
5 files changed, 115 insertions(+), 46 deletions(-)
diff --git a/[priyesh]ChangeLog b/[priyesh]ChangeLog
index d31b5fd..d826b4e 100644
--- a/[priyesh]ChangeLog
+++ b/[priyesh]ChangeLog
@@ -1,3 +1,21 @@
+2020-07-03 Priyesh Kumar <priyeshkkumar@gmail.com>
+
+ * Code Cleanup and Added more comments
+
+ * include/freetype/internal/ftdebug.h:
+ 1. Code Cleanup
+ 2. Reverted back to the original `ft_debug_init()` function
+ Added respective code inside `ft_debug_init()` to handle
+ default and custom trace levels in `ftdebug.c`
+ 3. Introduced variables to control logging.
+
+ * src/base/ftdebug.c:
+ 1. Updated definitions of following functions:
+ 1.1. ft_debug_init()
+ 1.2. FT_Trace_Set_Default_Level()
+ 1.3. FT_Trace_Set_Level
+ 2. Added more comments and Code Cleanup
+
2020-07-02 Priyesh Kumar <priyeshkkumar@gmail.com>
* Fixed some code layout
diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h
index 6c0b592..ee96db2 100644
--- a/include/freetype/ftlogging.h
+++ b/include/freetype/ftlogging.h
@@ -9,22 +9,33 @@ FT_BEGIN_HEADER
* level as an argument.
* User can also set the default trace level which is supplied by
* environment variable `FT2_DEBUG`
+ * See ftdebug.c for definitions
*
*/
- typedef void
- (*ft_ouput_handler)( const char* string );
-
FT_EXPORT( void )
FT_Trace_Set_Level( const char* level );
FT_EXPORT( void )
FT_Trace_Set_Default_Level( void );
+
+ /* An external callback function to be used to define an output handler */
+ typedef void
+ (*ft_custom_output_handler)( const char* string );
+
+
+ /**************************************************************************
+ *
+ * comments on callback
+ *
+ */
+ /*
FT_EXPORT( void )
FT_Trace_Set_Output( ft_ouput_handler handler );
FT_EXPORT( void )
FT_Trace_Set_Default_Output();
+ */
FT_END_HEADER
diff --git a/include/freetype/internal/ftdebug.h
b/include/freetype/internal/ftdebug.h
index 5524167..16b50cf 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -110,25 +110,10 @@ FT_BEGIN_HEADER
*/
#ifdef FT_LOGGING
-
- static ft_ouput_handler freetype_output_handler = NULL;
#undef FT_Log
#define FT_Log dlg_trace
-/****************************************************************************
- *
- * dlg uses output handlers to control how and where the log messages are
- * printed.
- * Therefore we need to define an output handler specific to FreeType, it
- * will act as a default output handler of Freetype.
- *
- */
-
- FT_BASE( void )
- ft_default_output_handler( const struct dlg_origin* origin,
- const char* string, void* data );
-
#else
#undef FT_Log
@@ -263,7 +248,7 @@ FT_BEGIN_HEADER
{ \
dlg_add_tag( "error_log", NULL ); \
dlg_trace varformat; \
- dlg_remove_tag( "error_log", NULL ); \
+ dlg_remove_tag( "error_log", NULL ); \
} while ( 0 )
#else
@@ -341,10 +326,49 @@ FT_BEGIN_HEADER
FT_BASE( void )
- ft_debug_init( const char* level );
+ ft_debug_init( void );
#ifdef FT_LOGGING
+
+/****************************************************************************
+ *
+ * dlg uses output handlers to control how and where the log messages are
+ * printed.
+ * Therefore we need to define an output handler specific to FreeType, it
+ * will act as a default output handler of Freetype.
+ *
+ */
+
+ FT_BASE( void )
+ ft_output_handler( const struct dlg_origin* origin, const char* string,
+ void* data );
+
+
+ /**************************************************************************
+ *
+ * Variable used when FT_LOGGING is enabled to control logging:
+ * 1. ft_default_trace_level: stores the value of trace levels which are
+ * provided to FreeType using FT2_DEBUG environment variable.
+ *
+ * 2. ft_custom_trace_level: stores the value of custom trace level which
+ * is provided by user at run-time.
+ *
+ * 3. custom_output_handler: stores the function pointer to the callback
+ * function provided by user.
+ *
+ * 4. ft_default_output_handler: stores the function pointer which is used
+ * internally by FreeType to print logs to file.
+ *
+ * 5. fileptr: store the FILE*
+ *
+ */
+ static const char* ft_default_trace_level = NULL;
+ static const char* ft_custom_trace_level = NULL;
+ static ft_custom_output_handler custom_output_handler = NULL;
+ static dlg_handler ft_default_output_handler = NULL;
+ static FILE* fileptr = NULL;
+
/**************************************************************************
*
* If FT_LOGGING macro is enabled, Freetype needs to initialize and
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index c5c0d12..9d629c1 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -193,9 +193,20 @@
* runtime errors), and 7 means _very_ verbose.
*/
FT_BASE_DEF( void )
- ft_debug_init( const char* level )
+ ft_debug_init( void )
{
- const char* ft2_debug = level;
+ const char* ft2_debug = NULL;
+
+#ifdef FT_LOGGING
+
+if( ft_custom_trace_level != NULL )
+ ft2_debug = ft_custom_trace_level;
+else
+ ft2_debug = ft_default_trace_level;
+
+#else
+ ft2_debug = ft_getenv( "FT2_DEBUG" );
+#endif /* FT_LOGGIGN */
if ( ft2_debug )
@@ -274,7 +285,7 @@
FT_BASE_DEF( void )
- ft_debug_init( const char* level )
+ ft_debug_init( void )
{
/* nothing */
}
@@ -316,31 +327,27 @@
#ifdef FT_LOGGING
-
- /**************************************************************************
- * If FT_LOGGING is enabled FreeType needs a FILE* to write logs
- * to file.
- */
- static FILE* fileptr = NULL;
-
-
-
/**************************************************************************
*
- * If FT_LOGGING is enabled, FreeType needs a FILE* to write logs
- * therefore it uses `ft_logging_init()` function to initialize a
- * FILE* and `ft_logging_deinit()` to un-initialize the FILE*
+ * If FT_LOGGING is enabled, FreeType needs to initialize all logging
+ * variables to write logs.
+ * Therefore it uses `ft_logging_init()` function to initialize a
+ * loggging variables and `ft_logging_deinit()` to un-initialize the
+ * logging variables.
*
*/
FT_BASE_DEF( void )
ft_logging_init( void )
{
+ ft_default_output_handler = &ft_output_handler;
+ ft_default_trace_level = ft_getenv( "FT2_DEBUG" );
fileptr = fopen( "freetype2.log", "w" );
- FT_Trace_Set_Default_Level();
+ ft_debug_init();
/* We need to set the default FreeType specific dlg's output handler */
- dlg_set_handler( &ft_default_output_handler, NULL );
+ dlg_set_handler( ft_default_output_handler, NULL );
+
}
FT_BASE_DEF( void )
@@ -356,7 +363,7 @@
*
*/
FT_BASE_DEF( void )
- ft_default_output_handler( const struct dlg_origin* origin,
+ ft_output_handler( const struct dlg_origin* origin,
const char* string, void* data )
{
unsigned int features;
@@ -375,39 +382,48 @@
/**************************************************************************
*
+ * Functions to set trace levels at run-time
+ * 1. FT_Trace_Set_Level() - Use this function to change the trace level
+ * at run-time. e.g. FT_Trace_Set_Level( "any:6 io:2" );
*
+ * 2. FT_Trace_Set_Default_Level() - Use this function to set the default
+ * value of trace levels which is provided by environment variable
+ * FT2_DEBUG
*
*/
+
FT_EXPORT_DEF( void )
FT_Trace_Set_Level( const char* level )
{
- ft_debug_init( level );
+ ft_custom_trace_level = level;
+ ft_debug_init();
}
FT_EXPORT_DEF( void )
FT_Trace_Set_Default_Level( void )
{
- ft_debug_init( ft_getenv( "FT2_DEBUG" ) );
+ ft_custom_trace_level = NULL ;
+ ft_debug_init();
}
/****************************************************************************
*
- *
+ * comments on callback
*
*/
-
+ /*
FT_EXPORT_DEF( void )
FT_Trace_Set_Output( ft_ouput_handler handler )
{
- freetype_output_handler = handler;
+ ft_custom_output_handler = handler;
}
FT_EXPORT_DEF( void )
FT_Trace_Set_Default_Output()
{
- freetype_output_handler = NULL;
+ ft_custom_output_handler = NULL;
}
-
+ */
#endif /* FT_LOGGING */
/* END */
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 9de8ac1..0217c51 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -5276,7 +5276,7 @@
#ifndef FT_LOGGING
#ifdef FT_DEBUG_LEVEL_ERROR
/* init debugging support */
- ft_debug_init( ft_getenv( "FT2_DEBUG" ) );
+ ft_debug_init();
#endif /* FT_DEBUG_LEVEL_ERROR */
#endif /* FT_LOGGING */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] priyesh_LogLibrary b378812: Updates on dynamic change of trace level,
Priyesh Kumar <=