Module: CassandraORM::Logger

Includes:
ActiveSupport::Benchmarkable
Included in:
Model
Defined in:
lib/cassandra-orm/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cassandra-orm/logger.rb', line 7

def self.included base
  base.extend self
  base.singleton_class.class_exec do
    def logger
      @logger ||= cluster.instance_variable_get :@logger
    end
    private :logger

    def execute identifier, statement, options = {}
      debug identifier, _fetch_cql(statement).strip, options[:arguments] do
        session.execute statement, options
      end
    end

    def execute_async identifier, statement, options = {}
      logger.info log_message(identifier, _fetch_cql(statement).strip, options[:arguments])
      session.execute_async statement, options
    end

    def _fetch_cql statement
      case statement
      when String, Cassandra::Statements::Simple then statement
      when Cassandra::Statements::Prepared, Cassandra::Statements::Bound then statement.cql
      when Cassandra::Statements::Batch then "[#{statement.statements.join('; ')}]"
      else statement.inspect
      end
    end
    private :_fetch_cql
  end
end

Instance Method Details

#execute(identifier, cql, options = {}) ⇒ Object



38
39
40
# File 'lib/cassandra-orm/logger.rb', line 38

def execute identifier, cql, options = {}
  self.class.execute identifier, cql, options
end

#execute_async(identifier, cql, options = {}) ⇒ Object



42
43
44
# File 'lib/cassandra-orm/logger.rb', line 42

def execute_async identifier, cql, options = {}
  self.class.execute_async identifier, cql, options
end