logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwilli...@apache.org
Subject svn commit: r1509519 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
Date Fri, 02 Aug 2013 03:07:03 GMT
Author: nickwilliams
Date: Fri Aug  2 03:07:02 2013
New Revision: 1509519

URL: http://svn.apache.org/r1509519
Log:
[LOG4J2-330] Adding a BSON Transformer for so that MongoDB can persist Log4j events

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java?rev=1509519&r1=1509518&r2=1509519&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/mongo/MongoDBConnection.java
Fri Aug  2 03:07:02 2013
@@ -16,9 +16,12 @@
  */
 package org.apache.logging.log4j.core.appender.db.nosql.mongo;
 
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.core.appender.db.nosql.NoSQLConnection;
 import org.apache.logging.log4j.core.appender.db.nosql.NoSQLObject;
+import org.bson.BSON;
+import org.bson.Transformer;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
@@ -32,6 +35,19 @@ import com.mongodb.WriteResult;
  * The MongoDB implementation of {@link NoSQLConnection}.
  */
 public final class MongoDBConnection implements NoSQLConnection<BasicDBObject, MongoDBObject>
{
+
+    static {
+        BSON.addDecodingHook(Level.class, new Transformer() {
+            @Override
+            public Object transform(Object o) {
+                if (o instanceof Level) {
+                    return ((Level) o).name();
+                }
+                return o;
+            }
+        });
+    }
+
     private final DBCollection collection;
     private final Mongo mongo;
     private final WriteConcern writeConcern;



Mime
View raw message