[base] Add public API to change the levels of tracing components. * include/freetype/ftlogging.h: New header file. * include/freetype/internal/ftdebug.h [FT_LOGGING]: Include `ftlogging.h`. * src/base/ftdebug.c (ft_custom_trace_level): New variable. (ft_debug_init): Update to support change of levels of tracing components of FreeType at run-time. (FT_Trace_Set_Level): New function to change the levels of tracing components at run-time. (FT_Trace_Set_Default_Level): New function to reset the levels of tracing components back to default.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
diff --git a/ChangeLog b/ChangeLog
index 7ab4f50..f3f113e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2020-11-28 Priyesh Kumar <priyeshkkumar@gmail.com>
+ [base] Add public API to change the levels of tracing components.
+
+ * include/freetype/ftlogging.h: New header file.
+
+ * include/freetype/internal/ftdebug.h [FT_LOGGING]: Include
+ `ftlogging.h`.
+
+ * src/base/ftdebug.c (ft_custom_trace_level): New variable.
+ (ft_debug_init): Update to support change of levels of tracing
+ components of FreeType at run-time.
+ (FT_Trace_Set_Level): New function to change the levels of tracing
+ components at run-time.
+ (FT_Trace_Set_Default_Level): New function to reset the levels of
+ tracing components back to default.
+
+2020-11-28 Priyesh Kumar <priyeshkkumar@gmail.com>
+
[base] Updates to print timestamp and name of `FT_COMPONENT` in logs.
* include/freetype/internal/ftdebug.h (FT_LOGGING_TAG,
diff --git a/include/freetype/ftchapters.h b/include/freetype/ftchapters.h
index 2a41fca..4f32cc8 100644
--- a/include/freetype/ftchapters.h
+++ b/include/freetype/ftchapters.h
@@ -124,6 +124,7 @@
* gzip
* lzw
* bzip2
+ * debugging_apis
*
*/
diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h
new file mode 100644
index 0000000..6f5c4f0
--- /dev/null
+++ b/include/freetype/ftlogging.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+ *
+ * ftlogging.h
+ *
+ * Additional debugging APIs.
+ *
+ * Copyright (C) 2020 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#ifndef FTLOGGING_H_
+#define FTLOGGING_H_
+
+
+#include <ft2build.h>
+#include FT_CONFIG_CONFIG_H
+
+
+FT_BEGIN_HEADER
+
+
+ /**************************************************************************
+ *
+ * @section:
+ * debugging_apis
+ *
+ * @title:
+ * External Debugging APIs
+ *
+ * @abstract:
+ * Public APIs to control the `FT_LOGGING` macro.
+ *
+ * @description:
+ * This section contains the declarations of public functions that
+ * enables fine control of what the `FT_LOGGING` macro outputs.
+ *
+ */
+
+
+ /**************************************************************************
+ *
+ * @function:
+ * FT_Trace_Set_Level
+ *
+ * @description:
+ * Change the levels of tracing components of FreeType at run time.
+ *
+ * @input:
+ * tracing_level ::
+ * New tracing value.
+ *
+ * @example:
+ * The following call makes FreeType trace everything but the 'memory'
+ * component.
+ *
+ * ```
+ * FT_Trace_Set_Level( "any:7 memory:0 );
+ * ```
+ *
+ * @note:
+ * This function is only available if compilation option `@FT_LOGGING`
+ * is set.
+ */
+ FT_EXPORT( void )
+ FT_Trace_Set_Level( const char* tracing_level );
+
+
+ /**************************************************************************
+ *
+ * @function:
+ * FT_Trace_Set_Default_Level
+ *
+ * @description:
+ * Reset tracing value of FreeType's components to the default value
+ * (i.e., to the value of the `FT2_DEBUG` environment value or to NULL
+ * if `FT2_DEBUG` is not set).
+ *
+ *
+ * @note:
+ * This function is only available if compilation option `@FT_LOGGING`
+ * is set.
+ */
+ FT_EXPORT( void )
+ FT_Trace_Set_Default_Level( void );
+
+ /* */
+
+
+FT_END_HEADER
+
+#endif /* FTLOGGING_H_ */
+
+
+/* END */
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 666c26d..8fe8846 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -34,7 +34,9 @@
#ifdef FT_LOGGING
#include <../src/dlg/dlg/dlg.h>
#include <../src/dlg/dlg/output.h>
-#endif
+
+#include <freetype/ftlogging.h>
+#endif /* FT_LOGGING */
FT_BEGIN_HEADER
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index e422bc2..f8d5f03 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -68,6 +68,9 @@
* 6. `ft_have_newline_char` is used to differentiate between a log
* message with and without a trailing newline character.
*
+ * 7. `ft_custom_trace_level` stores the custom trace level value, which
+ * is provided by the user at run-time.
+ *
* We use `static` to avoid 'unused variable' warnings.
*
*/
@@ -77,6 +80,7 @@
static FT_Bool ft_component_flag = FALSE;
static FT_Bool ft_timestamp_flag = FALSE;
static FT_Bool ft_have_newline_char = TRUE;
+ static const char* ft_custom_trace_level = NULL;
dlg_handler ft_default_log_handler = NULL;
@@ -232,8 +236,17 @@
FT_BASE_DEF( void )
ft_debug_init( void )
{
- const char* ft2_debug = ft_getenv( "FT2_DEBUG" );
+ 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
if ( ft2_debug )
{
@@ -479,6 +492,32 @@
dlg_remove_tag( tag, NULL );
}
+
+ /* documentation is in ftlogging.h */
+
+ FT_EXPORT_DEF( void )
+ FT_Trace_Set_Level( const char* level )
+ {
+ ft_component_flag = FALSE;
+ ft_timestamp_flag = FALSE;
+ ft_custom_trace_level = level;
+
+ ft_debug_init();
+ }
+
+
+ /* documentation is in ftlogging.h */
+
+ FT_EXPORT_DEF( void )
+ FT_Trace_Set_Default_Level( void )
+ {
+ ft_component_flag = FALSE;
+ ft_timestamp_flag = FALSE;
+ ft_custom_trace_level = NULL;
+
+ ft_debug_init();
+ }
+
#endif /* FT_LOGGING */