org.log4mongo
Class MongoDbAppender
java.lang.Object
org.apache.log4j.AppenderSkeleton
org.log4mongo.BsonAppender
org.log4mongo.MongoDbAppender
- All Implemented Interfaces:
- org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler
- Direct Known Subclasses:
- ExtendedMongoDbAppender, MongoDbPatternLayoutAppender
public class MongoDbAppender
- extends BsonAppender
Log4J Appender that writes log events into a MongoDB document oriented database. Log events are
fully parsed and stored as structured records in MongoDB (this appender does not require, nor use
a Log4J layout).
The appender does not create any indexes on the data that's stored - it is assumed that if
query performance is required, those would be created externally (e.g., in the MongoDB shell or
other external application).
- Author:
- Peter Monks (pmonks@gmail.com)
- See Also:
- Log4J
Appender Interface,
MongoDB
| Fields inherited from class org.apache.log4j.AppenderSkeleton |
closed, errorHandler, headFilter, layout, name, tailFilter, threshold |
| 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 |
MongoDbAppender
public MongoDbAppender()
requiresLayout
public boolean requiresLayout()
- Specified by:
requiresLayout in interface org.apache.log4j.Appender- Overrides:
requiresLayout in class BsonAppender
- See Also:
Appender.requiresLayout()
activateOptions
public void activateOptions()
- Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler- Overrides:
activateOptions in class org.apache.log4j.AppenderSkeleton
- See Also:
AppenderSkeleton.activateOptions()
getDatabase
protected com.mongodb.DB getDatabase(com.mongodb.Mongo mongo,
java.lang.String databaseName)
getMongo
protected com.mongodb.Mongo getMongo(java.util.List<com.mongodb.ServerAddress> addresses)
setCollection
public void setCollection(com.mongodb.DBCollection collection)
- Note: this method is primarily intended for use by the unit tests.
- Parameters:
collection - The MongoDB collection to use when logging events.
close
public void close()
- See Also:
Appender.close()
getHostname
public java.lang.String getHostname()
- Returns:
- The hostname of the MongoDB server (will not be null, empty or blank).
setHostname
public void setHostname(java.lang.String hostname)
- Parameters:
hostname - The MongoDB hostname to set (must not be null, empty or blank).
getPort
public java.lang.String getPort()
- Returns:
- The port of the MongoDB server (will be > 0).
setPort
public void setPort(java.lang.String port)
- Parameters:
port - The port to set (must not be null, empty or blank).
getDatabaseName
public java.lang.String getDatabaseName()
- Returns:
- The database used in the MongoDB server (will not be null, empty or blank).
setDatabaseName
public void setDatabaseName(java.lang.String databaseName)
- Parameters:
databaseName - The database to use in the MongoDB server (must not be null, empty or
blank).
getCollectionName
public java.lang.String getCollectionName()
- Returns:
- The collection used within the database in the MongoDB server (will not be null,
empty or blank).
setCollectionName
public void setCollectionName(java.lang.String collectionName)
- Parameters:
collectionName - The collection used within the database in the MongoDB server (must not be
null, empty or blank).
getUserName
public java.lang.String getUserName()
- Returns:
- The userName used to authenticate with MongoDB (may be null).
setUserName
public void setUserName(java.lang.String userName)
- Parameters:
userName - The userName to use when authenticating with MongoDB (may be null).
setPassword
public void setPassword(java.lang.String password)
- Parameters:
password - The password to use when authenticating with MongoDB (may be null).
getWriteConcern
public java.lang.String getWriteConcern()
- Returns:
- the writeConcern setting for Mongo.
setWriteConcern
public void setWriteConcern(java.lang.String writeConcern)
- Parameters:
writeConcern - The WriteConcern setting for Mongo.(may be null). If null, set to default of dbCollection's writeConcern.
getConcern
public com.mongodb.WriteConcern getConcern()
append
public void append(com.mongodb.DBObject bson)
- Description copied from class:
BsonAppender
- Method implemented by a concrete class to store the BSON object.
- Specified by:
append in class BsonAppender
- Parameters:
bson - The BSON object to insert into a MongoDB database collection.
isInitialized
public boolean isInitialized()
- Returns true if appender was successfully initialized. If this method returns false, the
appender should not attempt to log events.
- Returns:
- true if appender was successfully initialized
getCollection
protected com.mongodb.DBCollection getCollection()
- Returns:
- The MongoDB collection to which events are logged.
Copyright © 2013. All Rights Reserved.