freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2020-priyesh 593df37: [base] Updates to print timestamp


From: Priyesh Kumar
Subject: [freetype2] GSoC-2020-priyesh 593df37: [base] Updates to print timestamp and name of `FT_COMPONENT' in logs.
Date: Wed, 26 Aug 2020 08:39:22 -0400 (EDT)

branch: GSoC-2020-priyesh
commit 593df37ae76a4143e8043cb1d0df2d354d484df9
Author: Priyeshkkumar <priyeshkkumar@gmail.com>
Commit: Priyeshkkumar <priyeshkkumar@gmail.com>

    [base] Updates to print timestamp and name of `FT_COMPONENT' in logs.
    
        * include/freetype/internal/ftdebug.h (FT_LOGGING_TAG, FT_LOGGING_TAG_):
        New macros to resolve the value of `FT_COMPONENT' into a string.
        (ft_add_tag, ft_remove_tag): New functions to add and remove dlg tags.
    
        * src/base/ftdebug.c: Added new variables to control the logging of
        timestamp and name of `FT_COMPONENT' along with actual logs.
        (ft_add_tag, ft_remove_tag): Added function definition.
        (ft_log_handler): Updates to print timestamp and name of `FT_COMPONENT'.
        (ft_debug_init): If `FT_LOGGING' macro is defined users can now control
        the logging of timestamp and name of `FT_COMPONENT' by adding tags in
        environment variable `FT2_DEBUG'
---
 include/freetype/internal/ftdebug.h | 24 +++++++++++-
 src/base/ftdebug.c                  | 74 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/include/freetype/internal/ftdebug.h 
b/include/freetype/internal/ftdebug.h
index 35026a9..3c72149 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -105,6 +105,11 @@ FT_BEGIN_HEADER
 
 #ifdef FT_LOGGING
 
+  /* we need two macros to convert the names of `FT_COMPONENT' to a string */
+#define FT_LOGGING_TAG( x )  FT_LOGGING_TAG_( x )
+#define FT_LOGGING_TAG_( x ) #x
+
+
   /*************************************************************************
    *
    * If FT_LOGGING is enabled, trace messages will be sent to dlg's API and
@@ -117,12 +122,14 @@ FT_BEGIN_HEADER
 #define FT_LOG( level, varformat )                                         \
           do                                                               \
           {                                                                \
+            const char* dlg_tag =  FT_LOGGING_TAG( FT_COMPONENT );         \
+            ft_add_tag( dlg_tag );                                         \
             if( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level )  \
                 dlg_trace varformat;                                       \
+            ft_remove_tag( dlg_tag );                                      \
           }while( 0 )
 
 #else
-
 #define FT_LOG( level, varformat )                                         \
           do                                                               \
           {                                                                \
@@ -266,7 +273,10 @@ FT_BEGIN_HEADER
 #define FT_ERROR( varformat )                                               \
           do                                                                \
           {                                                                 \
+          const char* dlg_tag =  FT_LOGGING_TAG( FT_COMPONENT );            \
+          ft_add_tag( dlg_tag );                                            \
           dlg_trace varformat;                                              \
+          ft_remove_tag( dlg_tag );                                         \
           } while ( 0 )
 
 #else
@@ -388,6 +398,18 @@ FT_BEGIN_HEADER
   FT_BASE( void )
   ft_logging_deinit( void );
 
+  /**************************************************************************
+   *
+   * For printing the name of `FT_COMPONENT' along with the actual log, a dlg
+   * tag with the name of `FT_COMPONENT' needs to be added.
+   *
+   */
+  FT_BASE( void )
+  ft_add_tag( const char* tag );
+
+  FT_BASE( void )
+  ft_remove_tag( const char* tag );
+
 #endif /* FT_LOGGING */
 
 FT_END_HEADER
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 322dbb5..eb32239 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -55,12 +55,27 @@
    *
    * 2. ft_fileptr: store the FILE*
    *
+   * 3. ft_component: a string that holds the name of FT_COMPONENT
+   *
+   * 4. ft_component_flag: a flag when true, prints the name of
+   * FT_COMPONENT along with actual log message.
+   *
+   * 5. ft_timestamp_flag: a flag when true, prints time along with log
+   * actual log message.
+   *
+   * 6. 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 FILE* ft_fileptr = NULL;
+  static const char* ft_component = NULL;
+  static bool ft_component_flag = false;
+  static bool ft_timestamp_flag = false;
+  static bool ft_have_newline_char = true;
 
   dlg_handler ft_default_log_handler = NULL;
 
@@ -231,6 +246,36 @@
         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 /* FT_LOGGING */
+
         /* read toggle name, followed by ':' */
         q = p;
         while ( *p && *p != ':' )
@@ -379,11 +424,38 @@
                               const char* string, void* data )
   {
     ( void ) data;
-     const char*  features = "%c";
+     const char* features ;
+     if( ft_timestamp_flag && ft_component_flag && ft_have_newline_char )
+      features = "[%h:%m  %t]    %c";
+     else if( ft_component_flag && ft_have_newline_char)
+      features = "[%t]    %c";
+     else if( ft_timestamp_flag && ft_have_newline_char )
+      features = "[%h:%m]    %c";
+     else
+      features = "%c";
 
           dlg_generic_outputf_stream( ft_fileptr, features, origin, string,
                                 dlg_default_output_styles, true );
 
+
+     if( strchr( string, '\n' ) )
+       ft_have_newline_char = true;
+     else
+       ft_have_newline_char = false;
+
+  }
+
+  FT_BASE_DEF( void )
+  ft_add_tag( const char* tag )
+  {
+    ft_component = tag;
+    dlg_add_tag( tag, NULL );
+  }
+
+  FT_BASE_DEF( void )
+  ft_remove_tag( const char* tag )
+  {
+    dlg_remove_tag( tag, NULL );
   }
 
 #endif /* FT_LOGGING */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]