You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Al-Dhahir, Haitham" <Ha...@gs.com> on 2002/07/22 22:37:59 UTC

Using my own logging class for FOP

Hi,

I have two questions regarding FOP - they are not related, but I would
nonetheless be very grateful if anyone can help me with one or both of them!

1) I am running Java 1.3 and so I am using my own implementation of the Java
1.4 Logger class. My implementation works in exactly the same way as the
Java 1.4 version. How can I configure FOP to send all of its output to my
logger rather than System.out? I don't understand the code on the FOP
"embedding" html page.

2) I am parsing an XML file and converting it into PDF using FOP, embedded
with a Java application. One of the fields in my XML has "&#x0D;" as part of
the text; this is the Unicode carriage return character. I want this
carriage return to be preserved in the outputted PDF, so that my text
appears on two separate lines, but it is not. The text appears with a space
where the carriage return should be. How can I preserve the carriage return?

Many thanks in advance,

Haitham.

Re: Using my own logging class for FOP

Posted by Denis Balazuc <de...@videotron.ca>.
Hi

I can help on question 1...

My suggestion would be to encapsulate an instance of a
java.util.logging.Logger inside a class that extends org.apache.log.Logger
and have it forward every logging request to the java.util.logging.Logger.

(I'm just showing the implementation of ONE method....not all.... ;-))

java.util.logging.Logger javaLogger =
LogManager.getLogger("TheLoggerIWantToUseForFOP");


public class MixedLogger extends org.apache.log.Logger fopLogger
  private java.util.logging.Logger myLogger;
  public MixedLogger(java.util.logging.Logger logger) {
     super();
      myLogger = logger;
  }

 //override default LogKit behaviour - one method shown only !
  public void log(org.apache.log.Priority priority, String msg) {
    if (priority.equals(Priority.DEBUG)) {
      myLogger.log(java.util.logging.Level.INFO, msg);
    }
    else {
      //etc..
    }
  }
}


You can then use MixedLogger for FOP's driver.setLogger().
So basically, you delegate LogKit's calls to JDK Log's call by
encapsulation.....


An even faster solution (and more flexible imho), which is the other way
around, is to derive java.util.logging.Logger and have it implement
org.apache.log.LogTarget by implementing processEvent(LogEvent event);

public class MixedTarget extends java.util.logging.logger implements
org.apache.log.LogTarget {

  public processEvent(LogEvent event) {
    if (logEvent.getPriority().equals(Priority.DEBUG)) {
      //java logging ...
      log(java.util.logging.Level.INFO, msg);
    }
    else {
        //etc..
    }
  }
}

You then set FOP logger this way :

org.apache.log.Logger logger = new org.apache.log.Logger();
MixedTarget target = new MixedTarget();

logger.setLogTargets((LogTarget[]){target});

Driver fopDriver = new Driver();
driver.setLogger(logger)


..and have to set your new target for the JDK logging stuff...(which I don't
know how to do as I'm using Log4j, which is very close to LogKit)


However, the current Log Kit states that the LogTarget interface may turn
into an abstract class...so this would not compile anymore if it's going to
be the case.
This approach is better as you are sure you only need to implement only one
method.


Hope this helps

Cheers
Denis


----- Original Message -----
From: "Al-Dhahir, Haitham" <Ha...@gs.com>
To: <fo...@xml.apache.org>
Sent: Monday, July 22, 2002 4:37 PM
Subject: Using my own logging class for FOP


> Hi,
>
> I have two questions regarding FOP - they are not related, but I would
> nonetheless be very grateful if anyone can help me with one or both of
them!
>
> 1) I am running Java 1.3 and so I am using my own implementation of the
Java
> 1.4 Logger class. My implementation works in exactly the same way as the
> Java 1.4 version. How can I configure FOP to send all of its output to my
> logger rather than System.out? I don't understand the code on the FOP
> "embedding" html page.
>
> 2) I am parsing an XML file and converting it into PDF using FOP, embedded
> with a Java application. One of the fields in my XML has "&#x0D;" as part
of
> the text; this is the Unicode carriage return character. I want this
> carriage return to be preserved in the outputted PDF, so that my text
> appears on two separate lines, but it is not. The text appears with a
space
> where the carriage return should be. How can I preserve the carriage
return?
>
> Many thanks in advance,
>
> Haitham.