You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Jeremias Maerki <de...@greenmail.ch> on 2004/04/02 11:41:31 UTC

How to work with Commons Logging in FOP

As promised, I've changed the way the logger is fetched in the PDF
library and the font code. Instead of passing a Log instance from parent
to child (IoC, like with Avalon), logging-enabled classes fetch their
own logger via JCL's LogFactory. The code gets easier. I'm quite happy
with this.

As you may have seen I added a cvsignore file in the src directory. The
idea is to put a simplelog.properties (or other such configuration file) in
the src/private-resources directory so you can configure the SimpleLog
logger from Commons Logging.

My current simplelog.properties looks like this:
org.apache.commons.logging.simplelog.showShortLogname=false
org.apache.commons.logging.simplelog.defaultlog=info
org.apache.commons.logging.simplelog.log.org.apache.fop.pdf=trace

Info about simplelog.properties can be found at [1].

One additional thing is to add a system property to each startup
configuration in your IDE where you need to configure logging. Working
with Eclipse I've added...

-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

...to the "VM arguments" in the run configuration. This ensures that
Commons Logging will not use JDK 1.4 logging (see [2]), but directly
choose the SimpleLog implementation which is sufficient while developing.
Of course, you can use JDK 1.4 loggging or Log4J, as you wish. See the
javadocs for LogFactoryImpl [2] for further information. The whole
documentation on Commons Logging is available at it homepage [3].

[1] http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/impl/SimpleLog.html
[2] http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/impl/LogFactoryImpl.html
[3] http://jakarta.apache.org/commons/logging/


For setting up Commons Logging for a command-line application, please
see PFMReader and TTFReader for how I think it should be done. I'm not
entirely comfortable, yet, as SimpleLog logs everything to System.err.
For Barcode4J I wrote a special ConsoleLogger (for Avalon Logging) [4] that
logs only WARN, ERROR and FATAL levels to System.err while sending the
rest to System.out. Also, there's no possibility to get rid of the log
level prefix in SimpleLog. In the end, it would probably be best to
create a special CommandLineLog class which is tailored to this use case.

[4] http://cvs.sourceforge.net/viewcvs.py/barcode4j/barcode4j/src/java/org/krysalis/barcode4j/cli/AdvancedConsoleLogger.java?rev=1.1&view=auto

Jeremias Maerki


Re: How to work with Commons Logging in FOP

Posted by Jeremias Maerki <de...@greenmail.ch>.
On 02.04.2004 12:59:00 Chris Bowditch wrote:
> Jeremias Maerki wrote:
> 
> <snip/>
> 
> > As you may have seen I added a cvsignore file in the src directory. The
> > idea is to put a simplelog.properties (or other such configuration file) in
> > the src/private-resources directory so you can configure the SimpleLog
> > logger from Commons Logging.
> > 
> > My current simplelog.properties looks like this:
> > org.apache.commons.logging.simplelog.showShortLogname=false
> > org.apache.commons.logging.simplelog.defaultlog=info
> > org.apache.commons.logging.simplelog.log.org.apache.fop.pdf=trace
> > 
> > Info about simplelog.properties can be found at [1].
> 
> Well Ive created the file on my hard disk as you suggest. But shouldnt this 
> really be kept in CVS, with default settings. Obviously users will be expected 
>   to change the defaults. If a sample file is not kept in CVS, then every user 
> is going to have to look in archives in order to find out how to get logging 
> turned on. I know we dont have many users of HEAD yet, but I want us to 
> consider what is going to happen longer term .....

Well, JCL provides some reasonable default without any additional
configuration. I added the directory to cvsignore because I don't want
to accidently upload my private modifications to my log configuration.
If you think there should be a default configuration we can provide such
a file, but hopefully in a different directory.

> > 
> > One additional thing is to add a system property to each startup
> > configuration in your IDE where you need to configure logging. Working
> > with Eclipse I've added...
> > 
> > -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
> 
> We would need to add this to FOP.sh or FOP.bat in CVS

We could. But I expect a command-line application to write all its
output to System.out/err exclusively. See PFMReader and TTFReader where
I explicitely set up Commons Logging to write to the console. The system
property above is only necessary for embedded use.

> <snip/>
> 
> > For setting up Commons Logging for a command-line application, please
> > see PFMReader and TTFReader for how I think it should be done. I'm not
> > entirely comfortable, yet, as SimpleLog logs everything to System.err.
> > For Barcode4J I wrote a special ConsoleLogger (for Avalon Logging) [4] that
> > logs only WARN, ERROR and FATAL levels to System.err while sending the
> > rest to System.out. Also, there's no possibility to get rid of the log
> > level prefix in SimpleLog. In the end, it would probably be best to
> > create a special CommandLineLog class which is tailored to this use case.
> 
> Will embedded users be able to write a Logger that overrides the default 
> SimpleLog, and captures the output to file, rather than System.err?

Sure, they can use Log4J, LogKit, JDK 1.4 logging to write to any file,
email, SNMP or whatever. They don't even have to write a logger because
Log4J, for example, can already do everything. Just have a look at the
JCL documentation.


Jeremias Maerki


Re: How to work with Commons Logging in FOP

Posted by Chris Bowditch <bo...@hotmail.com>.
Glen Mazza wrote:

> Chris Bowditch wrote:

<snip/>

>>> -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog 
>>
>> We would need to add this to FOP.sh or FOP.bat in CVS
>>
> 
> It might be more efficient to store this information in the Ant build 
> file instead--I believe the .sh/.bat files just reference that file anyway.

Thanks Glen,

of course you are correct.

Chris



Re: How to work with Commons Logging in FOP

Posted by Glen Mazza <gr...@yahoo.com>.
Chris Bowditch wrote:

>>
>> One additional thing is to add a system property to each startup
>> configuration in your IDE where you need to configure logging. Working
>> with Eclipse I've added...
>>
>> -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog 
>>
>
>
> We would need to add this to FOP.sh or FOP.bat in CVS
>

It might be more efficient to store this information in the Ant build 
file instead--I believe the .sh/.bat files just reference that file anyway.

Glen

Re: How to work with Commons Logging in FOP

Posted by Chris Bowditch <bo...@hotmail.com>.
Jeremias Maerki wrote:

<snip/>

> As you may have seen I added a cvsignore file in the src directory. The
> idea is to put a simplelog.properties (or other such configuration file) in
> the src/private-resources directory so you can configure the SimpleLog
> logger from Commons Logging.
> 
> My current simplelog.properties looks like this:
> org.apache.commons.logging.simplelog.showShortLogname=false
> org.apache.commons.logging.simplelog.defaultlog=info
> org.apache.commons.logging.simplelog.log.org.apache.fop.pdf=trace
> 
> Info about simplelog.properties can be found at [1].

Well Ive created the file on my hard disk as you suggest. But shouldnt this 
really be kept in CVS, with default settings. Obviously users will be expected 
  to change the defaults. If a sample file is not kept in CVS, then every user 
is going to have to look in archives in order to find out how to get logging 
turned on. I know we dont have many users of HEAD yet, but I want us to 
consider what is going to happen longer term .....

> 
> One additional thing is to add a system property to each startup
> configuration in your IDE where you need to configure logging. Working
> with Eclipse I've added...
> 
> -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

We would need to add this to FOP.sh or FOP.bat in CVS

<snip/>

> For setting up Commons Logging for a command-line application, please
> see PFMReader and TTFReader for how I think it should be done. I'm not
> entirely comfortable, yet, as SimpleLog logs everything to System.err.
> For Barcode4J I wrote a special ConsoleLogger (for Avalon Logging) [4] that
> logs only WARN, ERROR and FATAL levels to System.err while sending the
> rest to System.out. Also, there's no possibility to get rid of the log
> level prefix in SimpleLog. In the end, it would probably be best to
> create a special CommandLineLog class which is tailored to this use case.

Will embedded users be able to write a Logger that overrides the default 
SimpleLog, and captures the output to file, rather than System.err?

Chris