OFBiz Tutorial: Store OFBiz logs in NoSql-Mongo DB

Arun PatidarPublished: Updated:

OFBiz Tutorial: Store OFBiz logs using NoSQL Mongo DBServers generate a large number of events (i.e. logging) that contain useful information about their operation including errors, warnings, and users behavior. By default, most servers, store these data in plain text log files on their local file systems. While plain-text logs are accessible and human-readable, they are difficult to use, reference, and analyze without holistic systems for aggregating and storing these data. —www.mongodb.org


This tutorial is the first in a multi-post tutorial series about utilizing MongoDB functionality for your OFBiz-based digital commerce solution. In today’s post we’ll show you how to store OFBiz logs in a NoSql-Mongo DB.

Why use a NoSQL database to store data logs?

Storing data logs in NoSQL databases such as Cassandra, CouchDB and MongoDB offers numerous advantages, including:

  • Traditional logging and I/O operations are often a bottleneck for capacity of applications
  • Ability to scale to support more data and concurrent threads
  • Logs don’t need to be archived, compressed or deleted on a regular basis as it happens with logs stored in text files
  • Logs in a NoSql database can easily be searched, filtered and analyzed

In this tutorial, we’ll show you how to store OFBiz logs in a NoSql database, specifically, MongoDB.

The following steps will describe how to setup MongoDB, Apache OFBiz, the Java Driver for MongoDB and the NoSql adapter for Apache Log4J, the logging framework used by OFBiz.

To store OFBiz logs in a NoSql database, follow these steps:
  1. Pre-requisites:
  1. Download the Mongo Java Driver (version 2.12.4) and copy it in the framework/base/lib directory
  2. Download “apache-log4j-2.1-bin.tar.gz” here. Extract the file and copy “log4j-nosql-2.1.jar” file from the extracted folder into framework/base/lib directory
  3. Start the MongoDB server by using command “mongod
  4. After successfully starting the MongoDB server, start Mongo Shell by issuing the command “mongo
  5. Create a new database or collection using the command “use ofbiz” (this command will determine whether or not the collection named “ofbiz” has already been created; if not, it will create the collection)
  6. Create a new database user for MongoDB using the following command:
  1. Now apply the following patch to OFBiz to configure the settings related to log4j: it will add a new appender to log4j, as shown below:
  1. Next, build and start an OFBiz trunk by using “./ant build start“. At this point, logs should be added to the “ofbiz” Mongo database in the collection named “applicationLog”.
  2. To check the logs that have been inserted into the MongoDB, you can use any one of the following commands:
Thanks for checking out our OFBiz Tutorial Series. In an upcoming blog we will describe how to create a screen in OFBiz and display the logs from MongoDB there.

About HotWax Systems

HotWax Systems, creator of HotWax Commerce, develops, implements, and supports fully customizable, enterprise-class, digital commerce platforms powered by Apache OFBiz. For more information about how to leverage the power and flexibility of OFBiz for your business, contact us for a free consultation.

Photo credit: neil cummings / Foter / CC BY-SA

Arun Patidar About Arun Patidar
Arun Patidar is a Manager of Enterprise Software Development with HotWax Systems. Arun is an e-commerce ERP enthusiast and full time developer with expertise on OFBiz. He enjoys participating in the OFBiz community and sharing his thoughts on new interventions in the OFBiz community.

Leave a Reply

Your email address will not be published. Required fields are marked *