Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MongoDBAppender added.

  • Loading branch information...
commit 8d134a9d3f705bdc6d882318d758ab73a3a95ae9 1 parent 37f83e5
@smilebase authored
View
1  .gitignore
@@ -0,0 +1 @@
+bin
View
7 logback.mongodb/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
28 logback.mongodb/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>logback.mongodb</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
3  logback.mongodb/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Mon Sep 19 19:58:25 CEST 2011
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
View
3  logback.mongodb/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,3 @@
+#Mon Sep 19 19:58:25 CEST 2011
+eclipse.preferences.version=1
+line.separator=\r\n
View
8 logback.mongodb/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Mon Sep 19 19:57:36 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
10 logback.mongodb/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Logback appender for mongoDB
+Bundle-SymbolicName: logback.mongodb
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Christian Trutz
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: ch.qos.logback.classic.spi,
+ ch.qos.logback.core,
+ com.mongodb
View
4 logback.mongodb/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
View
32 logback.mongodb/src/logback/mongodb/MongoDBAppender.java
@@ -0,0 +1,32 @@
+package logback.mongodb;
+
+import java.util.Date;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.UnsynchronizedAppenderBase;
+
+import com.mongodb.BasicDBObject;
+
+/**
+ * @author Christian Trutz
+ */
+public class MongoDBAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
+
+ private MongoDBConnectionSource connectionSource = null;
+
+ @Override
+ protected void append(ILoggingEvent eventObject) {
+ BasicDBObject logEntry = new BasicDBObject();
+ logEntry.append("message", eventObject.getFormattedMessage());
+ logEntry.append("logger", eventObject.getLoggerName());
+ logEntry.append("thread", eventObject.getThreadName());
+ logEntry.append("timestamp", new Date(eventObject.getTimeStamp()));
+ logEntry.append("level", eventObject.getLevel());
+ connectionSource.getDBCollection().insert(logEntry);
+ }
+
+ public void setConnectionSource(MongoDBConnectionSource connectionSource) {
+ this.connectionSource = connectionSource;
+ }
+
+}
View
66 logback.mongodb/src/logback/mongodb/MongoDBConnectionSource.java
@@ -0,0 +1,66 @@
+package logback.mongodb;
+
+import java.net.UnknownHostException;
+
+import com.mongodb.DBCollection;
+import com.mongodb.Mongo;
+import com.mongodb.MongoException;
+import com.mongodb.MongoURI;
+
+/**
+ * @author Christian Trutz
+ */
+public class MongoDBConnectionSource {
+
+ private volatile DBCollection dbCollection = null;
+
+ private String uri = null;
+
+ private String db = null;
+
+ private String collection = null;
+
+ protected DBCollection getDBCollection() {
+ DBCollection dbCollectionHelper = dbCollection;
+ if (dbCollectionHelper == null) {
+ synchronized (this) {
+ dbCollectionHelper = dbCollection;
+ if (dbCollectionHelper == null) {
+ try {
+ final Mongo mongo = new Mongo(new MongoURI(uri));
+ dbCollection = mongo.getDB(db)
+ .getCollection(collection);
+ Runtime.getRuntime().addShutdownHook(
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ mongo.close();
+ System.out
+ .println("Bye, bye mongo ...");
+ }
+ }, "mongo shutdown"));
+ } catch (MongoException mongoException) {
+ mongoException.printStackTrace();
+ } catch (UnknownHostException unknownHostException) {
+ unknownHostException.printStackTrace();
+ }
+ }
+ }
+ }
+ return dbCollectionHelper;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public void setDb(String db) {
+ this.db = db;
+ }
+
+ public void setCollection(String collection) {
+ this.collection = collection;
+ }
+
+}
View
8 logback.mongodb/targetPlatform/logback.mongodb.target
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?pde version="3.6"?>
+
+<target name="logback.mongodb" sequenceNumber="0">
+<locations>
+<location path="${project_loc:logback.mongodb}/targetPlatform" type="Directory"/>
+</locations>
+</target>
View
BIN  logback.mongodb/targetPlatform/plugins/logback-classic-0.9.29-sources.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/logback-classic-0.9.29.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/logback-core-0.9.29-sources.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/logback-core-0.9.29.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/mongo-2.6.5.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/slf4j-api-1.6.2-sources.jar
Binary file not shown
View
BIN  logback.mongodb/targetPlatform/plugins/slf4j-api-1.6.2.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.