summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyeshkkumar <priyeshkkumar@gmail.com>2020-07-13 18:37:34 +0530
committerPriyeshkkumar <priyeshkkumar@gmail.com>2020-07-13 18:37:34 +0530
commitafa548bb749b02af69b94153d3e08d146409643e (patch)
treef898f6bf8c6754cf0b069951c0a680ab22cfc71e
parent0c793e381c11591b1c648606763e20cfc2bbedcc (diff)
downloadfreetype2-afa548bb749b02af69b94153d3e08d146409643e.tar.gz
Added a flag to toggle ON/OFF the printing of FT_COMPONENT and Timestamp with actual log message
-rw-r--r--[priyesh]ChangeLog22
-rw-r--r--include/freetype/ftlogging.h3
-rw-r--r--include/freetype/internal/ftdebug.h67
-rw-r--r--src/base/ftdebug.c133
4 files changed, 178 insertions, 47 deletions
diff --git a/[priyesh]ChangeLog b/[priyesh]ChangeLog
index 43c9d5c57..503a99d6e 100644
--- a/[priyesh]ChangeLog
+++ b/[priyesh]ChangeLog
@@ -1,3 +1,25 @@
+2020-07-13 Priyesh Kumar <priyeshkkumar@gmail.com>
+
+ * include/freetype/ftlogging.h: Changed the definition of callback
+ function `ft_custom_log_handler` now it also provides FT_COMPONENT
+ value to the external log handeling function.
+
+ * include/freetype/internal/ftdebug.h:
+ 1. Added a function `FT_Callback()` which is used when user sets an
+ external log handeling callback function.
+ 2. Code Cleanup and resolved [ -Wunused-variable ] warnings
+ 3. Added a macro `FT_Log` to handle the `FT_TRACE`
+ * src/base/ftdebug.c:
+ 1. Updated code to print FT_COMPONENT and TimeStamp.
+ 2. Code Cleanup.
+ 3.Added support of flag within `FT2_DEBUG` env variable to control
+ the printing of extra info( time-stamp and FT_COMPONENT ):
+ 3.1 '-v' for printing FT_COMPONENT along with actual log message
+ 3.2 '-t' for printing TimeStamp along with actual log message
+ 3.3 '-tv' or '-vt' for printing both FT_COMPONENT and TimeStamp
+ along with actual log message.
+ 4. Added definition of function `FT_Callback()`
+
2020-07-04 Priyesh Kumar <priyeshkkumar@gmail.com>
* Added code to print FT_COMPONENT along with TimeStamp with each log
diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h
index 195d768ec..256a21d40 100644
--- a/include/freetype/ftlogging.h
+++ b/include/freetype/ftlogging.h
@@ -22,7 +22,8 @@ FT_BEGIN_HEADER
/* An external callback function to be used to define an output handler */
typedef void
- (*ft_custom_log_handler)( const char* fmt, va_list args );
+ (*ft_custom_log_handler)( const char* ft_component, const char* fmt,
+ va_list args );
/**************************************************************************
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 1722d3998..2f45ce40b 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -109,6 +109,40 @@ FT_BEGIN_HEADER
*
*/
+#ifdef FT_LOGGING
+
+#define FT_Log( level, varformat ) \
+ do \
+ { \
+ ft_add_tag( FT_LOGGING_TAG( FT_COMPONENT ) ); \
+ \
+ 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( FT_LOGGING_TAG( FT_COMPONENT ) ); \
+ }while( 0 )
+
+#else
+
+#define FT_Log( level, varformat ) \
+ do \
+ { \
+ if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \
+ { \
+ FT_Message varformat; \
+ } \
+ } while ( 0 )
+
+#endif /* FT_LOGGING */
+
+
+
+
#ifdef FT_DEBUG_LEVEL_TRACE
#define FT_LOGGING_TAG( x ) FT_LOGGING_TAG_( x )
@@ -126,16 +160,7 @@ ft_remove_tag( const char* tag );
#define FT_TRACE_COMP( x ) FT_TRACE_COMP_( x )
#define FT_TRACE_COMP_( x ) trace_ ## x
-#define FT_TRACE( level, varformat ) \
- do \
- { \
- if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \
- { \
- ft_add_tag( FT_LOGGING_TAG( FT_COMPONENT ) ); \
- FT_Message varformat; \
- ft_remove_tag( FT_LOGGING_TAG( FT_COMPONENT ) ); \
- } \
- } while ( 0 )
+#define FT_TRACE( level, varformat ) FT_Log( level, varformat )
#else /* !FT_DEBUG_LEVEL_TRACE */
@@ -351,26 +376,17 @@ ft_remove_tag( const char* tag );
/**************************************************************************
*
* 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
+ * 1. ft_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
+ * 2. ft_default_log_handler: stores the function pointer which is used
* internally by FreeType to print logs to file.
*
- * 5. ft_fileptr: store the FILE*
- *
+ * These are defined in ftdebug.c
*/
- static const char* ft_default_trace_level = NULL;
- static const char* ft_custom_trace_level = NULL;
- static ft_custom_log_handler custom_output_handler = NULL;
- static dlg_handler ft_default_log_handler = NULL;
- static FILE* ft_fileptr = NULL;
+ extern ft_custom_log_handler custom_output_handler;
+ extern dlg_handler ft_default_log_handler;
/**************************************************************************
*
@@ -386,6 +402,9 @@ ft_remove_tag( const char* tag );
FT_BASE( void )
ft_logging_deinit( void );
+ FT_BASE( void )
+ FT_Callback( const char* fmt, ... );
+
#endif /* FT_LOGGING */
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 74e967d9b..a1fc99ea5 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -44,6 +44,62 @@
#include <freetype/freetype.h>
#include <freetype/internal/ftdebug.h>
+#ifdef FT_LOGGING
+
+ /**************************************************************************
+ *
+ * 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. ft_component: a string that holds the name of FT_COMPONENT
+ *
+ * 4. ft_fileptr: store the FILE*
+ *
+ * 5. ft_component_flag: a flag when is true, prints FT_COMPONENT along
+ * with log message if `-v` is defined in FT2_DEBUG
+ * 6. ft_timestamp_flag: a flag when is true, prints time in millisec along
+ * with log message if `-t` is define in FT2_DEBUG
+ * 7. ft_have_newline_char: It is used to differentiate between a log
+ * message with '\n' char and log message without '\n' char
+ *
+ * Static Variables are defined here to remove [ -Wunused-variable ]
+ * warning
+ *
+ */
+ static const char* ft_default_trace_level = NULL;
+ static const char* ft_custom_trace_level = NULL;
+ static const char* ft_component = NULL;
+ static FILE* ft_fileptr = NULL;
+ static bool ft_component_flag = false;
+ static bool ft_timestamp_flag = false;
+ static bool ft_have_newline_char = true;
+
+ ft_custom_log_handler custom_output_handler = NULL;
+ dlg_handler ft_default_log_handler = NULL;
+
+ /* different types of dlg features to be used according to the flags */
+ /* passed in FT2_DEBUG environment variable */
+
+ static unsigned int features_component = dlg_output_threadsafe
+ | dlg_output_tags;
+ static unsigned int features_timestamp = dlg_output_threadsafe
+ | dlg_output_time
+ | dlg_output_time_msecs;
+ static unsigned int features_both = dlg_output_threadsafe
+ | dlg_output_time_msecs
+ |dlg_output_time
+ | dlg_output_tags ;
+ static unsigned int features_none = dlg_output_threadsafe;
+
+
+
+#endif
+
#ifdef FT_DEBUG_LEVEL_ERROR
@@ -53,25 +109,12 @@
FT_Message( const char* fmt,
... )
{
-#ifdef FT_LOGGING
-
- if( custom_output_handler != NULL )
- {
- va_list ap;
- va_start( ap, fmt );
- custom_output_handler( fmt, ap );
- va_end( ap );
- }
- else
- dlg_trace( fmt );
-#else
va_list ap;
va_start( ap, fmt );
vfprintf( stderr, fmt, ap );
va_end( ap );
-#endif /* FT_LOGGING */
}
@@ -230,10 +273,40 @@ else
for ( ; *p; p++ )
{
+
/* skip leading whitespace and separators */
if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
continue;
+#ifdef FT_LOGGING
+ /* check extra arguments for logging */
+ if( *p == '-' )
+ {
+ const char* r = ++p;
+ if( *r == 'v' )
+ {
+ ft_component_flag = true;
+ const char* s = ++r;
+ if( *s == 't' )
+ {
+ ft_timestamp_flag = true;
+ p++;
+ }
+ p++;
+ }
+ else if( *r == 't' )
+ {
+ ft_timestamp_flag = true;
+ const char* s = ++r;
+ if( *s == 'v' )
+ {
+ ft_component_flag = true;
+ p++;
+ }
+ p++;
+ }
+ }
+#endif
/* read toggle name, followed by ':' */
q = p;
while ( *p && *p != ':' )
@@ -379,18 +452,24 @@ else
ft_log_handler( const struct dlg_origin* origin,
const char* string, void* data )
{
- unsigned int features;
- if( origin->tags[0] == "error_log" )
- {
- features = dlg_output_threadsafe | dlg_output_tags ;
- }
+ static unsigned int features ;
+ if( ft_timestamp_flag && ft_component_flag && ft_have_newline_char )
+ features = features_both;
+ else if( ft_component_flag && ft_have_newline_char)
+ features = features_component;
+ else if( ft_timestamp_flag && ft_have_newline_char )
+ features = features_timestamp;
else
- {
- features = dlg_output_threadsafe | dlg_output_tags | dlg_output_time ;
- }
-
+ features = features_none;
+
+
dlg_generic_output_stream( ft_fileptr, features, origin, string,
dlg_default_output_styles );
+
+ if( strchr( string, '\n' ) )
+ ft_have_newline_char = true;
+ else
+ ft_have_newline_char = false;
}
/**************************************************************************
@@ -438,8 +517,18 @@ else
}
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 );
+ }
+
+ FT_BASE_DEF( void )
ft_add_tag( const char* tag )
{
+ ft_component = tag;
dlg_add_tag( tag, NULL );
}