xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: Unable to catch transformer Exception
Date Thu, 19 Mar 2009 11:21:56 GMT
For a client, I've once written three small helper classes that let you
intercept the Log4J messages. Here they are:

public interface ThreadLocalLogInterceptor {

    void log(String txt);
    
}

public class ThreadLocalLogSetup {

    private static ThreadLocal interceptorHolder = new ThreadLocal();
    
    public static ThreadLocalLogInterceptor installLogInterceptor(
            ThreadLocalLogInterceptor interceptor) {
        interceptorHolder.set(interceptor);
        return interceptor;
    }
    
    public static void uninstallLogInterceptor() {
        interceptorHolder.set(null);
    }
    
    public static ThreadLocalLogInterceptor getInterceptor() {
        return (ThreadLocalLogInterceptor)interceptorHolder.get();
    }
    
}

public class ThreadLocalAppender extends AppenderSkeleton {

    protected void append(LoggingEvent event) {
        ThreadLocalLogInterceptor interceptor = ThreadLocalLogSetup.getInterceptor();
        if (interceptor != null) {
            interceptor.log(event.getMessage().toString());
        }
        
    }

    public void close() {
        //nop
    }

    public boolean requiresLayout() {
        return true;
    }

}

You just implement the ThreadLocalLogInterceptor interface and install
it using ThreadLocalLogSetup.installLogInterceptor() (once per thread). 
Finally, you configure the ThreadLocalAppender in your Log4J
configuration.

Maybe that helps. Of course, you only get the plain log messages. You
still have to interpret them. It's just a hack but if you can't use the
new event system....

On 17.03.2009 06:44:37 Frank Niedermann wrote:
> 
> Hi Andreas,
> 
> 
> Andreas Delmelle-2 wrote:
> > 
> >> I get a planned Exception while invoking transformer.transform.
> >> Unfortunately I can not catch this Exception.
> > 
> > For FOP 0.95, I don't think it is possible to 'catch' the Exception,  
> > since it is never thrown. The Barcode4J extension causes an Exception,  
> > but FOP internally catches this and recovers. Unless you feel like  
> > working with a hacked FOP-version, or you can switch to FOP Trunk, I'm  
> > afraid you're stuck... :-/
> > 
> 
> I'm not allowed to use a hacked FOP-version as this is planned for a
> production environment. If I won't receive an exception, is it possible
> some how to query the log result (ERROR) and react on that?
> 
> Thanks,
>   Frank
> -- 
> View this message in context: http://www.nabble.com/Unable-to-catch-transformer-Exception-tp22537909p22552940.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message