logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Williams <nicho...@nicholaswilliams.net>
Subject Re: Two Question for NoSql MongoDB appender
Date Sat, 17 Aug 2013 14:37:26 GMT
YuCheng, LOG4J2-358 has been filed and fixed now. You can compile from trunk immediately to
get the fixes for both bugs (including LOG4J2-330, which was fixed a few weeks ago), or you
can wait for the next version to come out. Shouldn't be to much longer now.

N

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>
> 
> 
> 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();
>             }
>         });
> 
> 
> 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.
> 
> 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!
> 


Mime
View raw message