Search code examples
log4jibm-cloudcloudant

log4j with bluemix cloudant DB


I am trying to store log4j2 logs in bluemix's cloudant DB. Could you help me out or point to any document , regarding log4j2 configuration I need to make ?

Thank you.


Solution

  • Take a look at the Log4j 2 Docs - Appenders. The NoSQLAppender writes log events to a NoSQL database using an internal lightweight provider interface. Provider implementations currently exist for MongoDB and Apache CouchDB, and you can write a custom provider.

    You specify which NoSQL provider to use by specifying the appropriate configuration element within the <NoSql> element. The types currently supported are <MongoDb> and <CouchDb>. To create your own custom provider, read the JavaDoc for the NoSQLProvider, NoSQLConnection, and NoSQLObject classes and the documentation about creating Log4j plugins.

    Considering that Cloudant is built upon CouchDB you should be able to adapt the CouchDB appender for your purpose. The following is an example of appender configuration for CouchDB:

     <?xml version="1.0" encoding="UTF-8"?> 
       <Configuration status="error">  
         <Appenders>
            <NoSql name="databaseAppender">
              <CouchDb databaseName="applicationDb" protocol="https" server="couch.example.org" username="loggingUser" password="abc123" />
            </NoSql>   
         </Appenders>   
         <Loggers>
           <Root level="warn">
             <AppenderRef ref="databaseAppender"/>
           </Root>   
         </Loggers> 
       </Configuration>