org.log4mongo
Class MongoDbPatternLayoutAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.log4mongo.BsonAppender
          extended by org.log4mongo.MongoDbAppender
              extended by org.log4mongo.MongoDbPatternLayoutAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class MongoDbPatternLayoutAppender
extends MongoDbAppender

A Log4J Appender that uses a PatternLayout to write log events into a MongoDB database.

The conversion pattern specifies the format of a JSON document. The document can contain sub-documents and the elements can be strings or arrays.

For some Log4J appenders (especially file appenders) blank space padding is often used to get fields in adjacent rows to line up. For example, %-5p is often used to make all log levels the same width in characters. Since each value is stored in a separate property in the document, it usually doesn't make sense to use blank space padding with MongoDbPatternLayoutAppender.

The appender does not create any indexes on the data that's stored. If query performance is required, indexes must be created externally (e.g., in the mongo shell or an external reporting application).

Author:
Robert Stewart (robert@wombatnation.com)
See Also:
Log4J Appender Interface, MongoDB

Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
MongoDbPatternLayoutAppender()
           
 
Method Summary
protected  void append(org.apache.log4j.spi.LoggingEvent loggingEvent)
          Inserts a BSON representation of a LoggingEvent into a MongoDB collection.
 boolean requiresLayout()
           
 
Methods inherited from class org.log4mongo.MongoDbAppender
activateOptions, append, close, getCollection, getCollectionName, getConcern, getDatabase, getDatabaseName, getHostname, getMongo, getPort, getUserName, getWriteConcern, isInitialized, setCollection, setCollectionName, setDatabaseName, setHostname, setPassword, setPort, setUserName, setWriteConcern
 
Methods inherited from class org.log4mongo.BsonAppender
getBsonifier, setBsonifier
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoDbPatternLayoutAppender

public MongoDbPatternLayoutAppender()
Method Detail

requiresLayout

public boolean requiresLayout()
Specified by:
requiresLayout in interface org.apache.log4j.Appender
Overrides:
requiresLayout in class MongoDbAppender
See Also:
Appender.requiresLayout()

append

protected void append(org.apache.log4j.spi.LoggingEvent loggingEvent)
Inserts a BSON representation of a LoggingEvent into a MongoDB collection. A PatternLayout is used to format a JSON document containing data available in the LoggingEvent and, optionally, additional data returned by custom PatternConverters.

The format of the JSON document is specified in the .layout.ConversionPattern property.

Overrides:
append in class BsonAppender
Parameters:
loggingEvent - The LoggingEvent that will be formatted and stored in MongoDB
See Also:
AppenderSkeleton.append(org.apache.log4j.spi.LoggingEvent)


Copyright © 2013. All Rights Reserved.