Several inline comments.

On Aug 16, 2013, at 6:43 PM, Gary Gregory wrote:

> Make sure you can see the messages from the status logger, maybe there is an 
> error processing the log4j config file early on.

There are no messages from the status logger.

> G
> 
> 
> On Fri, Aug 16, 2013 at 7:38 PM, Remko Popma <remko.po...@gmail.com> wrote:
> What is this " LoggingTest.cleanupClass:49 NullPointer" at the bottom of your 
> list of errors? What does that do?

The NPE is coming from the method that cleans up after all the tests in the 
class have run. I'm ignoring this error. It doesn't happen if the tests pass, 
so obviously the problem is the tests, not the NPE in the cleanup method. It's 
just a symptom of the test failures, not a symptom of the underlying problem.

> 
> 
> On Sat, Aug 17, 2013 at 8:27 AM, Gary Gregory <garydgreg...@gmail.com> wrote:
> It's likely that MongoDB needs another jar on the CP.

Doesn't appear so. Otherwise MongoException would be found BUT one of its 
dependencies would trigger a NoClassDefFoundError. Plus, I've looked through 
the code. The only dependencies that it has that aren't in the same JAR are 
dependencies that com.mongodb.DB also has. So therefore they aren't the cause 
of the problem, or it would fail even without my new code.

Here is the entire stack trace of one of the failures. They all look identical 
to this, minus different test names / methods that they call.

testTraceWithException(org.apache.log4j.LoggerTest)  Time elapsed: 0.137 sec  
<<< ERROR!
java.lang.NoClassDefFoundError: com/mongodb/MongoException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:171)
        at 
org.apache.logging.log4j.core.config.plugins.PluginManager.decode(PluginManager.java:232)
        at 
org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:151)
        at 
org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:129)
        at 
org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:116)
        at 
org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:102)
        at 
org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:183)
        at 
org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:115)
        at 
org.apache.logging.log4j.core.layout.PatternLayout.createLayout(PatternLayout.java:218)
        at 
org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:51)
        at 
org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:63)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:204)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:101)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:67)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:83)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:200)
        at org.apache.log4j.Logger$PrivateManager.getContext(Logger.java:61)
        at org.apache.log4j.Logger.getRootLogger(Logger.java:47)
        at 
org.apache.log4j.LoggerTest.testTraceWithException(LoggerTest.java:415)

> 
> G
> 
> 
> On Fri, Aug 16, 2013 at 6:48 PM, Nick Williams 
> <nicho...@nicholaswilliams.net> wrote:
> Guys, I'm having a hard time with this simple fix that should have taken five 
> minutes. I'm getting test failures due to NoClassDefFoundErrors that 
> shouldn't happen.
> 
> Here are the tests in error:
>   CategoryTest.setupClass:52 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testTraceWithException:415 ? NoClassDefFound 
> com/mongodb/MongoExcep...
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testLog:459 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testRB1:295 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testRB2:314 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testRB3:334 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testTrace:388 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testAdditivity1:119 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testAdditivity2:144 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testAdditivity3:183 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testIsTraceEnabled:443 ? NoClassDefFound 
> com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.testExists:355 ? NoClassDefFound com/mongodb/MongoException
>   LoggerTest.tearDown:75 ? NoClassDefFound com/mongodb/MongoException
>   LoggingTest.setupClass:44 ? NoClassDefFound com/mongodb/MongoException
>   LoggingTest.cleanupClass:49 NullPointer
> 
> Here's the code I added:
> 
>                 try {
>                     if (!database.authenticate(username, 
> password.toCharArray())) {
>                         LOGGER.error("Failed to authenticate against MongoDB 
> server. Unknown error.");
>                     }
>                 } catch (MongoException e) {
>                     LOGGER.error("Failed to authenticate against MongoDB: " + 
> e.getMessage(), e);
>                 } catch (IllegalStateException e) {
>                     LOGGER.error("Factory-supplied MongoDB database 
> connection already authenticated with different" +
>                             "credentials but lost connection.");
>                 }
> 
> Problem is, "database" is an instance of com.mongodb.DB, which is in the same 
> JAR as com.mongodb.MongoException. If I remove this code, the tests pass. How 
> is this possible? The DB instance is there with or without this new code, 
> which means the JAR is on the classpath, which means MongoException should be 
> on the classpath.
> 
> Very confused...
> 
> Nick
> 
> On Aug 16, 2013, at 5:13 PM, Gary Gregory wrote:
> 
>> Thank you for the update Nick!
>> :)
>> Gary
>> 
>> 
>> On Fri, Aug 16, 2013 at 5:39 PM, Nick Williams 
>> <nicho...@nicholaswilliams.net> wrote:
>> Answers inline.
>> 
>> On Aug 14, 2013, at 2:10 AM, YuCheng Ting wrote:
>> 
>>> Hi all,
>>> 
>>> I use beta8 log4j2 and wrote log4j2.xml like example in document 
>>> (http://logging.apache.org/log4j/2.x/manual/appenders.html#NoSQLAppender ):
>>> 
>>> 
>>> <appenders>
>>>     <NoSql name="databaseAppender">
>>>         <MongoDb databaseName="applicationDb" 
>>> collectionName="applicationLog"
>>>             server="mongo.example.org"
>>>             username="loggingUser" password="abc123" />
>>>     </NoSql>
>>> </appenders>
>> 
>> Yep. That's correct.
>> 
>>> but I get the two exception:
>>> 
>>> 1, "can't serialize class org.apache.logging.log4j.Level" exception in 
>>> (BasicBSONEncoder.java:270), I read the code and add follow code in my 
>>> project before logging, it gone.
>>> 
>>>         BSON.addEncodingHook(org.apache.logging.log4j.Level.class, new 
>>> Transformer() {
>>>             @Override
>>>             public Object transform(Object o) {
>>>                 return o.toString();
>>>             }
>>>         });
>> 
>> This bug was reported and fixed a few weeks ago. The fix will be in the next 
>> version, or you can compile locally. 
>> https://issues.apache.org/jira/browse/LOG4J2-330
>> 
>>> 2, “not authorized for insert test.log”, because my MongoDB need auth to 
>>> write, but the the "username" and "password" attributes in log4j2.xml is 
>>> nearly useless, after I read source code, found it NOT auth in 
>>> 
>>> org.apache.logging.log4j.core.appender.db.nosql.mongo.MongoDBProvider.createNoSQLProvider
>>> source code line 181 after check username and password and 
>>> com.mongodb.DB.authenticate never be called.
>> 
>> This is a bug. I'm reporting it and fixing it now. The fix will be in the 
>> next version, or you can compile locally (after I get the change committed, 
>> of course).
>> 
>>> so I change log4j2.xml :
>>> 
>>> <NoSql name="mongodb">
>>>              <MongoDb collectionName="log" databaseName="test"
>>>                          factoryClassName="com.yuchs.test.log4j.MainTest"
>>>                         factoryMethodName="getMongoClient" />
>>> </NoSql>
>>> 
>>> and create MongoClient and call com.mongodb.DB.authenticate method in 
>>> com.yuchs.test.log4j.MainTest.getMongoClient.
>>> 
>>> 
>>> This is my question:
>>> 
>>> 1, Why not add BSON.addEncodingHook code into log4j2 project to avoid basic 
>>> exception ? or another rule of method I don't know ?
>>> 
>>> 2, Why not auth DB in log4j2 project if password and username is set in 
>>> log4j2.xml ? or another rule of method I don't know ?
>>> 
>>> Thanks everyone!
>>> 
>> 
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Reply via email to