DATE: Apr 29, 2015
AUTHOR: Arun Patidar
Servers 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.
Storing data logs in NoSQL databases such as Cassandra, CouchDB and MongoDB offers numerous advantages, including:
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.
j = {user:"ofbiz", pwd:"ofbiz", roles:["readWrite"]} db.addUser(j)
Index: framework/base/config/log4j2.xml =================================================================== --- framework/base/config/log4j2.xml (revision 1651591) +++ framework/base/config/log4j2.xml (working copy) @@ -33,10 +33,15 @@ </Policies> <DefaultRolloverStrategy max="3"/> </RollingFile> + <NoSql name="databaseAppender"> + <MongoDb databaseName="ofbiz" collectionName="applicationLog" server="localhost" + username="ofbiz" password="ofbiz" /> + </NoSql> <Async name="async"> <AppenderRef ref="ofbiz"/> <AppenderRef ref="stdout"/> <AppenderRef ref="error"/> + <AppenderRef ref="databaseAppender"/> </Async> </Appenders> <Loggers>
db.applicationLog.find() db.applicationLog.find().pretty() db.applicationLog.find({},{ISODate:1, loggerName:1, message:1, _id:0})
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.
HotWax Systems, creator of Apache OFBiz Accelerator, 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