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<http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory