Commit ff40776591f215a05c0ed1bf49069090e5180578

Werner Lemberg 2021-06-25T09:19:51

[base] Add trace level to logging output. Some practical debugging work has shown that displaying level X of an `FT_TRACEX` macro in the output of `FT2_DEBUG="... -v"` would be very helpful to find out which trace level should be selected. As an example, we now get output like ``` [ttobjs:2] TTF driver [ttobjs:2] SFNT driver [sfobjs:2] not a font using the SFNT container format [t1objs:2] Type 1 driver [stream:7] FT_Stream_EnterFrame: 14 bytes ``` * include/freetype/internal/ftdebug.h (FT_LOGGING_TAGX): New macro. (FT_LOG): Use it to add the trace level to the logging tag. * include/freetype/internal/fttrace.h (FT_MAX_TRACE_LEVEL_LENGTH): Adjust. * docs/DEBUG: Updated.

diff --git a/ChangeLog b/ChangeLog
index a792f06..ab619cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2021-06-25  Werner Lemberg  <wl@gnu.org>
+
+	[base] Add trace level to logging output.
+
+	Some practical debugging work has shown that displaying level X of
+	an `FT_TRACEX` macro in the output of `FT2_DEBUG="...  -v"` would be
+	very helpful to find out which trace level should be selected.  As
+	an example, we now get output like
+
+	```
+	[ttobjs:2]    TTF driver
+	[ttobjs:2]      SFNT driver
+	[sfobjs:2]      not a font using the SFNT container format
+	[t1objs:2]    Type 1 driver
+	[stream:7]    FT_Stream_EnterFrame: 14 bytes
+	```
+
+	* include/freetype/internal/ftdebug.h (FT_LOGGING_TAGX): New macro.
+	(FT_LOG): Use it to add the trace level to the logging tag.
+
+	* include/freetype/internal/fttrace.h (FT_MAX_TRACE_LEVEL_LENGTH):
+	Adjust.
+
+	* docs/DEBUG: Updated.
+
 2021-06-24  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
 	[smooth, raster] Fix up and align error codes.
diff --git a/docs/DEBUG b/docs/DEBUG
index 9a5fdc6..4f35877 100644
--- a/docs/DEBUG
+++ b/docs/DEBUG
@@ -168,7 +168,7 @@ behaviour of FreeType at runtime.
     If `FT_DEBUG_LOGGING' is defined, two more options are available.
 
     * -v: Print also  the name of FreeType's component  from which the
-          current log is produced.
+          current log is produced, together with the tracing level.
 
     * -t: Print also the time.
 
@@ -176,7 +176,7 @@ behaviour of FreeType at runtime.
 
       FT2_DEBUG="any:7 memory:5 -vt"
 
-        => [20:32:02:44969 ttload]    table directory loaded
+        => [20:32:02:44969 ttload:2]    table directory loaded
 
       FT2_DEBUG="any:7 memory:5 -t"
 
@@ -184,7 +184,7 @@ behaviour of FreeType at runtime.
 
       FT2_DEBUG="any:7 memory:5 -v"
 
-        => [ttload]    table directory loaded
+        => [ttload:2]    table directory loaded
 
 
   FT_LOGGING_FILE
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 1b6aec3..b9787a7 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -114,11 +114,16 @@ FT_BEGIN_HEADER
 #define FT_LOGGING_TAG( x )   FT_LOGGING_TAG_( x )
 #define FT_LOGGING_TAG_( x )  #x
 
+  /* we need two macros to convert the component and the trace level */
+  /* to a string that combines them                                  */
+#define FT_LOGGING_TAGX( x, y )   FT_LOGGING_TAGX_( x, y )
+#define FT_LOGGING_TAGX_( x, y )  #x ":" #y
+
 
 #define FT_LOG( level, varformat )                                         \
           do                                                               \
           {                                                                \
-            const char*  dlg_tag = FT_LOGGING_TAG( FT_COMPONENT );         \
+            const char*  dlg_tag = FT_LOGGING_TAGX( FT_COMPONENT, level ); \
                                                                            \
                                                                            \
             ft_add_tag( dlg_tag );                                         \
diff --git a/include/freetype/internal/fttrace.h b/include/freetype/internal/fttrace.h
index 6b1019e..2ed205e 100644
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -19,8 +19,9 @@
   /* definitions of trace levels for FreeType 2 */
 
   /* the maximum string length (if the argument to `FT_TRACE_DEF` */
-  /* gets used as a string)                                       */
-#define FT_MAX_TRACE_LEVEL_LENGTH  9
+  /* gets used as a string) plus one charachter for ':' plus      */
+  /* another one for the trace level                              */
+#define FT_MAX_TRACE_LEVEL_LENGTH  (9 + 1 + 1)
 
   /* the first level must always be `trace_any' */
 FT_TRACE_DEF( any )