Skip to content

azizabah/logback-mongodb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

logback.mongodb

This project contains a "Logback":http://logback.qos.ch/ "appender":http://logback.qos.ch/manual/appenders.html for "mongoDB":http://www.mongodb.org/.

Configuration

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.

Building

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.

logback.xml

<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>

Maven Dependency

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.

Checking the logs

Query the logs from Mongo commandline:
$ mongo
> use logdb
> db.logs.count()
> db.logs.find()

About

Logback appender for mongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%