[gdal-dev] Redirect CPLDebug output?
Frank Warmerdam
warmerdam at pobox.com
Thu Sep 8 11:09:12 EDT 2011
On 11-09-08 07:48 AM, Jim Pendleton wrote:
> Is there any model for redirecting CPLDebug output from stdout to an
> alternative path?
>
> Since I have no command line or stdout in my Android activity where I call GDAL
> as a library, “|” and “>” are not available.
>
> I’d like the option to send the output of CPLDebug to Android’s LogCat or even
> to an output file, if required.
>
> I confess to being a C++ lightweight, in addition to having a lack of expertise
> in GDAL, so port/cpl_port.h’s syntax for CPL_PRINT_FUNC_FORMAT at the root of
> the definition of CPLDebug has me flummoxed:
>
> #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__
> (__printf__, format_idx, arg_idx)))
>
> The __android_log_print() function for sending output to the LogCat stream is
> similar to printf(), but with two extra initial arguments that I could in
> theory hardwire for my own purposes in an ifdef so existing calls to CPL_DEBUG
> throughout GDAL would not need to be modified.
>
> Conceptually, but not syntactically, in cpl_port.h I would like an overriding
> definition something like this:
Jim,
There is no need to overwrite the high level CPLError and CPLDebug functions.
Instead install a handler for the messages with CPLSetErrorHandler(). If
you look in gdal/port/cpl_error.cpp you can see two error handlers - the
CPLDefaultErrorHandler() and the CPLLoggingErrorHandler() as examples. The
error handler declaration should look like:
void CPL_STDCALL CPLAndroidErrorHandler( CPLErr eErrClass, int nError,
const char * pszErrorMsg )
{
}
Note that the error message comes in preformatted for you with the exception
that it is up to you to report the error type (one of which is CE_Debug) and
the error number if you want.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/warmerda
and watch the world go round - Rush | Geospatial Software Developer
More information about the gdal-dev
mailing list