Details
Description
Seems like NoSQLAppender can't insert any log events to Mongo due to lack of serializer for Level enum.
2013-07-31 18:19:27,831 ERROR An exception occurred processing Appender databaseAppender java.lang.IllegalArgumentException: can't serialize class org.apache.logging.log4j.Level
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:270)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:174)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:120)
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
at com.mongodb.OutMessage.putObject(OutMessage.java:289)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:239)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
at com.mongodb.DBCollection.insert(DBCollection.java:148)
at com.mongodb.DBCollection.insert(DBCollection.java:91)
at org.apache.logging.log4j.core.appender.db.nosql.mongo.MongoDBConnection.insertObject(MongoDBConnection.java:61)
Here is my config
<configuration status="WARN">
<appenders>
<NoSql name="databaseAppender" suppressExceptions="true">
<MongoDb collectionName="applicationLog" factoryClassName="com.borsch.DBManager" factoryMethodName="getNewMongoClient" writeConcernConstant="NONE" username="root" password="qwe"/>
</NoSql>
</appenders>
<loggers>
<root level="error">
<appender-ref ref="databaseAppender"/>
</root>
</loggers>
</configuration>
For now I used following workaround (code is in Scala)
class LevelBSONEncoder extends org.bson.Transformer { def transform(o: Any): AnyRef = o match { case level: org.apache.logging.log4j.Level => new java.lang.Integer(level.intLevel()) } } // which is used like this org.bson.BSON.addEncodingHook(org.apache.logging.log4j.Level.ERROR.getClass, new LevelBSONEncoder())
I think it should be done in appender.