lib/semantic_logger/appender/mongodb.rb in semantic_logger-0.3.3 vs lib/semantic_logger/appender/mongodb.rb in semantic_logger-0.4.0
- old
+ new
@@ -107,12 +107,15 @@
# * No indexes by default (not even on _id)
# * Documents cannot be deleted,
# * Document updates cannot make them any larger
# * Documents are always stored in insertion order
# * A find will always return the documents in their insertion order
+ #
+ # Creates an index based on tags to support faster lookups
def create_indexes
db.create_collection(collection_name, {:capped => true, :size => @collection_size, :max => @collection_max})
+ collection.ensure_index('tags')
end
# Purge all data from the capped collection by dropping the collection
# and recreating it.
# Also useful when the size of the capped collection needs to be changed
@@ -167,9 +170,19 @@
end
# Strip the standard Rails colorizing from the logged message
def self.strip_colorizing(message)
message.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip
+ end
+
+ # Default host_name to use if none is supplied to the appenders initializer
+ def self.host_name
+ @@host_name ||= Socket.gethostname.split('.').first
+ end
+
+ # Override the default host_name
+ def self.host_name=(host_name)
+ @@host_name = host_name
end
# Log the message to MongoDB
def log(log)
# Insert log entry into Mongo
\ No newline at end of file