This project contains a "Logback":http://logback.qos.ch/ "appender":http://logback.qos.ch/manual/appenders.html for "mongoDB":http://www.mongodb.org/.
If you add
<appender name="MONGO" class="logback.mongodb.MongoDBAppender">
<connectionSource class="logback.mongodb.MongoDBConnectionSource">
<uri>mongodb://localhost</uri>
<db>logdb</db>
<collection>logs</collection>
</connectionSource>
</appender>
p. into your @logback.xml@ or @logback-test.xml@ file, Logback will connect to @mongodb://localhost@ server and append your logs into @logdb@ mongo database using the @logs@ collection. Please see also "mongoDB connection documentation":http://www.mongodb.org/display/DOCS/Connections for more and detailed infos on mongo URIs.
mvn clean install
To use the Logback.MongoDB Configure the appender as above, however you may find it easier to configure using the port 127.0.0.1 instead of using localhost.
<appender name="MONGO" class="logback.mongodb.MongoDBAppender">
<connectionSource class="logback.mongodb.MongoDBConnectionSource">
<uri>mongodb://127.0.0.1</uri>
<db>logdb</db>
<collection>logs</collection>
</connectionSource>
</appender>
...
<root level="trace">
<appender-ref ref="console"/>
<appender-ref ref="MONGO"/>
</root>
Add to your project's pom.xml
<dependency>
<groupId>logback.mongodb</groupId>
<artifactId>logback.mongodb</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
Run the application or test that logs.
Query the logs from Mongo commandline:
$ mongo
> use logdb
> db.logs.count()
> db.logs.find()