maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lennart Jörelid <lennart.jore...@gmail.com>
Subject Best practises for manipulating the JUL Logger in a Plugin
Date Mon, 02 Feb 2015 15:07:17 GMT
Hello all,

I'm in the final phase of revamping the Jaxb2-Maven-Plugin, and have
encountered a (presumably) common problem. The plugin delegates most of its
work to the JDK-distributed tools XJC and SchemaGen. These two tools use
JUL for logging; and their respective outputs should be emitted onto the
Maven Log for debugging and clarity.

Writing a small Handler which delegates the JUL LogRecords to the active
Maven Log is trivial - but I wonder if I need to reset the JUL root logger
after the tool has been run, or if that is done automagically by Maven.

Basically - will the next downstream plugin which needs to wrap a tool
using JUL be affected by my fiddlings according to the snippet below?

// Redirect the JUL Logging statements to the Maven Log.
final Logger rootLogger = Logger.getLogger("");
rootLogger.setLevel(Level.FINER);
for(Handler current : rootLogger.getHandlers()) {
    rootLogger.removeHandler(current);
}
rootLogger.addHandler(new MavenLogHandler(getLog(), "XJC", getEncoding(false)));

// Fire XJC
if (XJC_COMPLETED_OK != Driver.run(xjcArguments, new
XjcLogAdapter(getLog()))) { ... display error message ... }

The approach works as expected - the boldfaced logging statements below are
harvested from the XJC tool being put to work by the jabx2-maven-plugin:

[DEBUG] Created episode directory
[/Users/lj/Development/Projects/Codehaus/github_jaxb2_plugin/target/it/xjc-include-xsds-in-artifact/target/generated-sources/jaxb/META-INF]:
true
[DEBUG] Using explicitly configured encoding [UTF-8]





*[DEBUG] [XJC]: feb 02, 2015 3:51:53 EM com.sun.xml.bind.v2.util.XmlFactory
createSchemaFactoryFIN: SchemaFactory instance:
com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory@5b6813df[DEBUG]
[XJC]: feb 02, 2015 3:51:53 EM com.sun.xml.bind.v2.util.XmlFactory
allowExternalAccessFIN: Property
"http://javax.xml.XMLConstants/property/accessExternalSchema
<http://javax.xml.XMLConstants/property/accessExternalSchema>" is supported
and has been successfully set by used JAXP implementation.*

-- 

--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: lj@jguru.se
| URL:   www.jguru.se
| Phone
| (skype):    jgurueurope
| (intl):     +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message