[base] Add functions and variables to print logs to a file.
* include/freetype/internal/ftdebug.h: Added dlg's header files. (FT_LOG): New macro to redirect trace logs to dlg's API's whenever `FT_LOGGING' is defined. (ft_logging_init, ft_logging_deinit): New functions to handle initialization and uninitialization of logging related variables. (ft_log_handler): New function to handle logs of FreeType. * src/base/ftdebug.c: Add necessary logging related variables. (ft_logging_init, ft_logging_deinit, ft_log_handler): Add function definitions. * src/base/ftinit.c (FT_Init_FreeType) [FT_LOGGING]: Call `ft_logging_init`. (FT_Done_FreeType) [FT_LOGGING]: Call `ft_logging_deinit`. * src/base/ftobjs.c (FT_New_Library): Call `ft_debug_init` only if `FT_LOGGING` is not defined.
This commit is contained in:
parent
34b1c897c1
commit
d46bada285
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,25 @@
|
||||||
|
2020-11-27 Priyesh Kumar <priyeshkkumar@gmail.com>
|
||||||
|
|
||||||
|
[base] Add functions and variables to print logs to a file.
|
||||||
|
|
||||||
|
* include/freetype/internal/ftdebug.h: Added dlg's header files.
|
||||||
|
(FT_LOG): New macro to redirect trace logs to dlg's API's whenever
|
||||||
|
`FT_LOGGING' is defined.
|
||||||
|
(ft_logging_init, ft_logging_deinit): New functions to handle
|
||||||
|
initialization and uninitialization of logging related variables.
|
||||||
|
(ft_log_handler): New function to handle logs of FreeType.
|
||||||
|
|
||||||
|
* src/base/ftdebug.c: Add necessary logging related variables.
|
||||||
|
(ft_logging_init, ft_logging_deinit, ft_log_handler): Add function
|
||||||
|
definitions.
|
||||||
|
|
||||||
|
* src/base/ftinit.c (FT_Init_FreeType) [FT_LOGGING]: Call
|
||||||
|
`ft_logging_init`.
|
||||||
|
(FT_Done_FreeType) [FT_LOGGING]: Call `ft_logging_deinit`.
|
||||||
|
|
||||||
|
* src/base/ftobjs.c (FT_New_Library): Call `ft_debug_init` only if
|
||||||
|
`FT_LOGGING` is not defined.
|
||||||
|
|
||||||
2020-11-27 Priyesh Kumar <priyeshkkumar@gmail.com>
|
2020-11-27 Priyesh Kumar <priyeshkkumar@gmail.com>
|
||||||
|
|
||||||
[builds] Necessary changes to make 'dlg' compile.
|
[builds] Necessary changes to make 'dlg' compile.
|
||||||
|
@ -38,7 +60,7 @@
|
||||||
|
|
||||||
* src/cff/cffobjs.c (cff_iriver_init): Always default to Adobe engine.
|
* src/cff/cffobjs.c (cff_iriver_init): Always default to Adobe engine.
|
||||||
* src/cid/cidobjs.c (cid_driver_init): Ditto.
|
* src/cid/cidobjs.c (cid_driver_init): Ditto.
|
||||||
* src/type1/t1objs.c (T1_Driver_Init): Ditto.
|
* src/type1/t1objs.c (T1_Driver_Init): Ditto.
|
||||||
|
|
||||||
2020-11-09 Werner Lemberg <wl@gnu.org>
|
2020-11-09 Werner Lemberg <wl@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,21 @@
|
||||||
|
|
||||||
#include "compiler-macros.h"
|
#include "compiler-macros.h"
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
#include <../src/dlg/dlg/dlg.h>
|
||||||
|
#include <../src/dlg/dlg/output.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
FT_BEGIN_HEADER
|
FT_BEGIN_HEADER
|
||||||
|
|
||||||
|
/* force the definition of FT_DEBUG_LEVEL_TRACE if FT_LOGGING is */
|
||||||
|
/* already defined. */
|
||||||
|
/* */
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
#undef FT_DEBUG_LEVEL_TRACE
|
||||||
|
#define FT_DEBUG_LEVEL_TRACE
|
||||||
|
#endif
|
||||||
|
|
||||||
/* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */
|
/* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */
|
||||||
/* is already defined; this simplifies the following #ifdefs */
|
/* is already defined; this simplifies the following #ifdefs */
|
||||||
|
@ -84,18 +96,42 @@ FT_BEGIN_HEADER
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* If FT_LOGGING is enabled, tracing messages are sent to dlg's API.
|
||||||
|
* If FT_LOGGING is disabled, tracing messages are sent to `FT_Message`
|
||||||
|
* (defined in ftdebug.c).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
|
||||||
|
#define FT_LOG( level, varformat ) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \
|
||||||
|
dlg_trace varformat; \
|
||||||
|
} while( 0 )
|
||||||
|
|
||||||
|
#else /* !FT_LOGGING */
|
||||||
|
|
||||||
|
#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
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
||||||
|
|
||||||
/* we need two macros here to make cpp expand `FT_COMPONENT' */
|
/* we need two macros here to make cpp expand `FT_COMPONENT' */
|
||||||
#define FT_TRACE_COMP( x ) FT_TRACE_COMP_( x )
|
#define FT_TRACE_COMP( x ) FT_TRACE_COMP_( x )
|
||||||
#define FT_TRACE_COMP_( x ) trace_ ## x
|
#define FT_TRACE_COMP_( x ) trace_ ## x
|
||||||
|
|
||||||
#define FT_TRACE( level, varformat ) \
|
#define FT_TRACE( level, varformat ) FT_LOG( level, varformat )
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \
|
|
||||||
FT_Message varformat; \
|
|
||||||
} while ( 0 )
|
|
||||||
|
|
||||||
#else /* !FT_DEBUG_LEVEL_TRACE */
|
#else /* !FT_DEBUG_LEVEL_TRACE */
|
||||||
|
|
||||||
|
@ -204,7 +240,27 @@ FT_BEGIN_HEADER
|
||||||
|
|
||||||
#ifdef FT_DEBUG_LEVEL_ERROR
|
#ifdef FT_DEBUG_LEVEL_ERROR
|
||||||
|
|
||||||
#define FT_ERROR( varformat ) FT_Message varformat
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* If FT_LOGGING is enabled, error messages are sent to dlg's API.
|
||||||
|
* If FT_LOGGING is disabled, error messages are sent to `FT_Message`
|
||||||
|
* (defined in ftdebug.c).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
|
||||||
|
#define FT_ERROR( varformat ) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
dlg_trace varformat; \
|
||||||
|
} while ( 0 )
|
||||||
|
|
||||||
|
#else /* !FT_LOGGING */
|
||||||
|
|
||||||
|
#define FT_ERROR( varformat ) FT_Message varformat
|
||||||
|
|
||||||
|
#endif /* !FT_LOGGING */
|
||||||
|
|
||||||
|
|
||||||
#else /* !FT_DEBUG_LEVEL_ERROR */
|
#else /* !FT_DEBUG_LEVEL_ERROR */
|
||||||
|
|
||||||
|
@ -277,6 +333,48 @@ FT_BEGIN_HEADER
|
||||||
FT_BASE( void )
|
FT_BASE( void )
|
||||||
ft_debug_init( void );
|
ft_debug_init( void );
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* 'dlg' uses output handlers to control how and where log messages are
|
||||||
|
* printed. Therefore we need to define a default output handler for
|
||||||
|
* FreeType.
|
||||||
|
*/
|
||||||
|
FT_BASE( void )
|
||||||
|
ft_log_handler( const struct dlg_origin* origin,
|
||||||
|
const char* string,
|
||||||
|
void* data );
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* `ft_default_log_handler` stores the function pointer that is used
|
||||||
|
* internally by FreeType to print logs to a file.
|
||||||
|
*
|
||||||
|
* It is defined in `ftdebug.c`.
|
||||||
|
*/
|
||||||
|
extern dlg_handler ft_default_log_handler;
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* If FT_LOGGING macro is enabled, FreeType needs to initialize and
|
||||||
|
* un-initialize `FILE*`.
|
||||||
|
*
|
||||||
|
* These functions are defined in `ftdebug.c`.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
FT_BASE( void )
|
||||||
|
ft_logging_init( void );
|
||||||
|
|
||||||
|
FT_BASE( void )
|
||||||
|
ft_logging_deinit( void );
|
||||||
|
|
||||||
|
#endif /* FT_LOGGING */
|
||||||
|
|
||||||
|
|
||||||
FT_END_HEADER
|
FT_END_HEADER
|
||||||
|
|
||||||
#endif /* FTDEBUG_H_ */
|
#endif /* FTDEBUG_H_ */
|
||||||
|
|
|
@ -45,6 +45,28 @@
|
||||||
#include <freetype/internal/ftdebug.h>
|
#include <freetype/internal/ftdebug.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Variables used to control logging.
|
||||||
|
*
|
||||||
|
* 1. `ft_default_trace_level` stores the value of trace levels, which are
|
||||||
|
* provided to FreeType using the `FT2_DEBUG` environment variable.
|
||||||
|
*
|
||||||
|
* 2. `ft_fileptr` stores the `FILE*` handle.
|
||||||
|
*
|
||||||
|
* Use `static` to avoid 'unused variable' warnings.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static const char* ft_default_trace_level = NULL;
|
||||||
|
static FILE* ft_fileptr = NULL;
|
||||||
|
|
||||||
|
dlg_handler ft_default_log_handler = NULL;
|
||||||
|
|
||||||
|
#endif /* FT_LOGGING*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef FT_DEBUG_LEVEL_ERROR
|
#ifdef FT_DEBUG_LEVEL_ERROR
|
||||||
|
|
||||||
/* documentation is in ftdebug.h */
|
/* documentation is in ftdebug.h */
|
||||||
|
@ -106,7 +128,6 @@
|
||||||
#endif /* FT_DEBUG_LEVEL_ERROR */
|
#endif /* FT_DEBUG_LEVEL_ERROR */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FT_DEBUG_LEVEL_TRACE
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
||||||
|
|
||||||
/* array of trace levels, initialized to 0; */
|
/* array of trace levels, initialized to 0; */
|
||||||
|
@ -315,4 +336,59 @@
|
||||||
#endif /* !FT_DEBUG_LEVEL_TRACE */
|
#endif /* !FT_DEBUG_LEVEL_TRACE */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Initialize and de-initialize 'dlg' library.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FT_BASE_DEF( void )
|
||||||
|
ft_logging_init( void )
|
||||||
|
{
|
||||||
|
ft_default_log_handler = ft_log_handler;
|
||||||
|
ft_default_trace_level = ft_getenv( "FT2_DEBUG" );
|
||||||
|
|
||||||
|
if ( ft_getenv( "FT_LOGGING_FILE" ) )
|
||||||
|
ft_fileptr = ft_fopen( ft_getenv( "FT_LOGGING_FILE" ), "w" );
|
||||||
|
else
|
||||||
|
ft_fileptr = stderr;
|
||||||
|
|
||||||
|
ft_debug_init();
|
||||||
|
|
||||||
|
/* Set the default output handler for 'dlg'. */
|
||||||
|
dlg_set_handler( ft_default_log_handler, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FT_BASE_DEF( void )
|
||||||
|
ft_logging_deinit( void )
|
||||||
|
{
|
||||||
|
ft_fclose( ft_fileptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* An output log handler for FreeType.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
FT_BASE_DEF( void )
|
||||||
|
ft_log_handler( const struct dlg_origin* origin,
|
||||||
|
const char* string,
|
||||||
|
void* data )
|
||||||
|
{
|
||||||
|
const char* features = "%c";
|
||||||
|
|
||||||
|
FT_UNUSED( data );
|
||||||
|
|
||||||
|
|
||||||
|
dlg_generic_outputf_stream( ft_fileptr, features, origin, string,
|
||||||
|
dlg_default_output_styles, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FT_LOGGING */
|
||||||
|
|
||||||
|
|
||||||
/* END */
|
/* END */
|
||||||
|
|
|
@ -202,6 +202,10 @@
|
||||||
FT_Memory memory;
|
FT_Memory memory;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
ft_logging_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* check of `alibrary' delayed to `FT_New_Library' */
|
/* check of `alibrary' delayed to `FT_New_Library' */
|
||||||
|
|
||||||
/* First of all, allocate a new system object -- this function is part */
|
/* First of all, allocate a new system object -- this function is part */
|
||||||
|
@ -248,6 +252,10 @@
|
||||||
/* discard memory manager */
|
/* discard memory manager */
|
||||||
FT_Done_Memory( memory );
|
FT_Done_Memory( memory );
|
||||||
|
|
||||||
|
#ifdef FT_LOGGING
|
||||||
|
ft_logging_deinit();
|
||||||
|
#endif
|
||||||
|
|
||||||
return FT_Err_Ok;
|
return FT_Err_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5292,10 +5292,12 @@
|
||||||
if ( !memory || !alibrary )
|
if ( !memory || !alibrary )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
|
||||||
|
#ifndef FT_LOGGING
|
||||||
#ifdef FT_DEBUG_LEVEL_ERROR
|
#ifdef FT_DEBUG_LEVEL_ERROR
|
||||||
/* init debugging support */
|
/* init debugging support */
|
||||||
ft_debug_init();
|
ft_debug_init();
|
||||||
#endif
|
#endif /* FT_DEBUG_LEVEL_ERROR */
|
||||||
|
#endif /* !FT_LOGGING */
|
||||||
|
|
||||||
/* first of all, allocate the library object */
|
/* first of all, allocate the library object */
|
||||||
if ( FT_NEW( library ) )
|
if ( FT_NEW( library ) )
|
||||||
|
|
Loading…
Reference in New Issue