Page 1 of 1

Logging and Netbeans Platform

PostPosted: Fri Apr 05, 2013 12:30 am
by reno
How can I disable logging (or set logging level to "error") in Netbeans platform application? I use docx4j in my application as a library wrapper module. I guess the proper way would be to set correct logging levels in log4j config file and include it in classpath. If I put log4j.xml inside some module's jar file, log4j fails to load it and throws MalformedURLException. The reason why it does that is because the path to the jar file contains illegal characters (eg. 'ö' and 'ä' in 'c:/työryhmä/myApp/modules/module.jar'). Users might install my application to any directory, so avoiding "wrong" characters in path name is not possible.

I tried also to put log4j.xml to my application's (root) directory and pass path to the file at startup using parameter -J-Dlog4j.configuration=log4j.xml . This doesn't cause exception but obviously doesn't work since docx4j gives message "Log4jConfigurator .configure line 45 - Since your log4j configuration (if any) was not found, docx4j has configured log4j automatically."

I searched the forums and only workaround I found is setting log level manually in code. Eg.:
org.apache.log4j.Logger.getRootLogger().setLevel( org.apache.log4j.Level.ERROR );

Is there any better ways to fix this?

Re: Logging and Netbeans Platform

PostPosted: Fri Apr 05, 2013 8:27 am
by jason
Seems a strange error to me. Are you sure it is characters like 'ö' and 'ä' which is causing the problem? It would be interesting to see the where in log4j source code the problem is (from the stack trace).

I think you are likely to get more responses if you post this question on StackOverflow using tags such as log4j, character-encoding, docx4j, and perhaps netbeans-7 or netbeans-platform

You can prevent docx4j from configuring log4j automatically, by setting the relevsant property in docx4j.properties file

Re: Logging and Netbeans Platform

PostPosted: Fri Apr 05, 2013 6:38 pm
by reno
jason wrote:Seems a strange error to me. Are you sure it is characters like 'ö' and 'ä' which is causing the problem? It would be interesting to see the where in log4j source code the problem is (from the stack trace).
Here's the stack trace:

Code: Select all
log4j:ERROR Could not parse url [jar:file:/C:/työryhmä/myApp/modules/module.jar!/log4j.xml].
com.sun.org.apache.xerces.internal.util.URI$MalformedURIException: Opaque part contains invalid character: ö
   at com.sun.org.apache.xerces.internal.util.URI.initializePath(URI.java:1137)
   at com.sun.org.apache.xerces.internal.util.URI.initialize(URI.java:581)
   at com.sun.org.apache.xerces.internal.util.URI.<init>(URI.java:334)
   at com.sun.org.apache.xerces.internal.util.URI.<init>(URI.java:297)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.expandSystemIdStrictOff1(XMLEntityManager.java:2145)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.expandSystemId(XMLEntityManager.java:1977)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:948)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1151)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1049)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:962)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
   at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:237)
   at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
   at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
   at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:690)
   at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:789)
   at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:696)
   at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
   at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
   at org.apache.log4j.Logger.getLogger(Logger.java:118)
   at org.docx4j.jaxb.Context.<clinit>(Context.java:47)


I think you are likely to get more responses if you post this question on StackOverflow using tags such as log4j, character-encoding, docx4j, and perhaps netbeans-7 or netbeans-platform

You can prevent docx4j from configuring log4j automatically, by setting the relevsant property in docx4j.properties file
Do you mean setting the docx4j.Log4j.Configurator.disabled to "true"? Before my first post I tried that too and it didn't work. I must have done something wrong back then because now it works, don't know why.. Oh well, it doesn't matter since I got it working now! Thanks for the help!