Sha256: d8493a7c375bc4b2fd3ddf439665099e00cd94b776e21ed6772e60423aff2f4b

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# Adapted from https://github.com/le0pard/mongodb_logger

module MongoRequestLogger
  module Adapters
    class Base
      DEFAULT_CAP_SIZE = 100

      attr_reader :configuration, :connection, :connection_type, :collection, :authenticated

      def collection_name
        options[:collection] || 'server_log'
      end

      # Capsize in bytes
      def capsize
        cap = options[:capsize] || DEFAULT_CAP_SIZE
        cap * 1024 * 1024
      end

      def authenticated?
        @authenticated
      end

      def check_for_collection
        # setup the capped collection if it doesn't already exist
        create_collection unless @connection.collection_names.include?(collection_name)
        @collection = @connection[collection_name]
      end

      def reset_collection
        if @connection && @collection
          @collection.drop
          create_collection
        end
      end

      def reconnect

      end

      def collection_stats_hash(stats)
        {
            :is_capped => (stats["capped"] && ([1, true].include?(stats["capped"]))),
            :count => stats["count"].to_i,
            :size => stats["size"].to_f,
            :storageSize => stats["storageSize"].to_f,
            :collection => collection_name
        }
      end

      def create_collection
        raise "Not implemented"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongo_request_logger-0.8.0 lib/mongo_request_logger/adapters/base.rb
mongo_request_logger-0.7.0 lib/mongo_request_logger/adapters/base.rb
mongo_request_logger-0.6.0 lib/mongo_request_logger/adapters/base.rb