Updates on dynamic change of trace level

This commit is contained in:
Priyeshkkumar 2020-07-03 15:00:27 +05:30
parent fde1c1698d
commit b378812f22
5 changed files with 115 additions and 46 deletions

View File

@ -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> 2020-07-02 Priyesh Kumar <priyeshkkumar@gmail.com>
* Fixed some code layout * Fixed some code layout

View File

@ -9,22 +9,33 @@ FT_BEGIN_HEADER
* level as an argument. * level as an argument.
* User can also set the default trace level which is supplied by * User can also set the default trace level which is supplied by
* environment variable `FT2_DEBUG` * environment variable `FT2_DEBUG`
* See ftdebug.c for definitions
* *
*/ */
typedef void
(*ft_ouput_handler)( const char* string );
FT_EXPORT( void ) FT_EXPORT( void )
FT_Trace_Set_Level( const char* level ); FT_Trace_Set_Level( const char* level );
FT_EXPORT( void ) FT_EXPORT( void )
FT_Trace_Set_Default_Level( 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_EXPORT( void )
FT_Trace_Set_Output( ft_ouput_handler handler ); FT_Trace_Set_Output( ft_ouput_handler handler );
FT_EXPORT( void ) FT_EXPORT( void )
FT_Trace_Set_Default_Output(); FT_Trace_Set_Default_Output();
*/
FT_END_HEADER FT_END_HEADER

View File

@ -110,25 +110,10 @@ FT_BEGIN_HEADER
*/ */
#ifdef FT_LOGGING #ifdef FT_LOGGING
static ft_ouput_handler freetype_output_handler = NULL;
#undef FT_Log #undef FT_Log
#define FT_Log dlg_trace #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 #else
#undef FT_Log #undef FT_Log
@ -263,7 +248,7 @@ FT_BEGIN_HEADER
{ \ { \
dlg_add_tag( "error_log", NULL ); \ dlg_add_tag( "error_log", NULL ); \
dlg_trace varformat; \ dlg_trace varformat; \
dlg_remove_tag( "error_log", NULL ); \ dlg_remove_tag( "error_log", NULL ); \
} while ( 0 ) } while ( 0 )
#else #else
@ -341,10 +326,49 @@ FT_BEGIN_HEADER
FT_BASE( void ) FT_BASE( void )
ft_debug_init( const char* level ); ft_debug_init( void );
#ifdef FT_LOGGING #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 * If FT_LOGGING macro is enabled, Freetype needs to initialize and

View File

@ -193,9 +193,20 @@
* runtime errors), and 7 means _very_ verbose. * runtime errors), and 7 means _very_ verbose.
*/ */
FT_BASE_DEF( void ) 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 ) if ( ft2_debug )
@ -274,7 +285,7 @@
FT_BASE_DEF( void ) FT_BASE_DEF( void )
ft_debug_init( const char* level ) ft_debug_init( void )
{ {
/* nothing */ /* nothing */
} }
@ -316,31 +327,27 @@
#ifdef FT_LOGGING #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 * If FT_LOGGING is enabled, FreeType needs to initialize all logging
* therefore it uses `ft_logging_init()` function to initialize a * variables to write logs.
* FILE* and `ft_logging_deinit()` to un-initialize the FILE* * 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_BASE_DEF( void )
ft_logging_init( 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" ); 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 */ /* 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 ) FT_BASE_DEF( void )
@ -356,7 +363,7 @@
* *
*/ */
FT_BASE_DEF( void ) 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 ) const char* string, void* data )
{ {
unsigned int features; 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_EXPORT_DEF( void )
FT_Trace_Set_Level( const char* level ) FT_Trace_Set_Level( const char* level )
{ {
ft_debug_init( level ); ft_custom_trace_level = level;
ft_debug_init();
} }
FT_EXPORT_DEF( void ) FT_EXPORT_DEF( void )
FT_Trace_Set_Default_Level( 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_EXPORT_DEF( void )
FT_Trace_Set_Output( ft_ouput_handler handler ) FT_Trace_Set_Output( ft_ouput_handler handler )
{ {
freetype_output_handler = handler; ft_custom_output_handler = handler;
} }
FT_EXPORT_DEF( void ) FT_EXPORT_DEF( void )
FT_Trace_Set_Default_Output() FT_Trace_Set_Default_Output()
{ {
freetype_output_handler = NULL; ft_custom_output_handler = NULL;
} }
*/
#endif /* FT_LOGGING */ #endif /* FT_LOGGING */
/* END */ /* END */

View File

@ -5276,7 +5276,7 @@
#ifndef FT_LOGGING #ifndef FT_LOGGING
#ifdef FT_DEBUG_LEVEL_ERROR #ifdef FT_DEBUG_LEVEL_ERROR
/* init debugging support */ /* init debugging support */
ft_debug_init( ft_getenv( "FT2_DEBUG" ) ); ft_debug_init();
#endif /* FT_DEBUG_LEVEL_ERROR */ #endif /* FT_DEBUG_LEVEL_ERROR */
#endif /* FT_LOGGING */ #endif /* FT_LOGGING */