Class: Cequel::Metal::RequestLogger Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cequel/metal/request_logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The Logger class encapsulates logging functionality for Keyspace.

Since:

  • 1.0.0

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequestLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RequestLogger.

Since:

  • 1.0.0

API:

  • private



17
18
19
# File 'lib/cequel/metal/request_logger.rb', line 17

def initialize
  self.slowlog_threshold = 2000
end

Instance Attribute Details

#logger::Logger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns An instance of Logger that responds to methods for standard severity levels.

Returns:

  • An instance of Logger that responds to methods for standard severity levels

Since:

  • 1.0.0

API:

  • private



13
14
15
# File 'lib/cequel/metal/request_logger.rb', line 13

def logger
  @logger
end

#slowlog_thresholdInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Only log queries that take longer than threshold ms.

Returns:

  • Only log queries that take longer than threshold ms

Since:

  • 1.0.0

API:

  • private



15
16
17
# File 'lib/cequel/metal/request_logger.rb', line 15

def slowlog_threshold
  @slowlog_threshold
end

Instance Method Details

#log(label, statement, *bind_vars) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Log a CQL statement

Parameters:

  • a logical label for this statement

  • the CQL statement to log

  • bind variables for the CQL statement

Since:

  • 1.0.0

API:

  • private



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cequel/metal/request_logger.rb', line 29

def log(label, statement, *bind_vars)
  return yield if logger.nil?

  response = nil
  begin
    time = Benchmark.ms { response = yield }
    generate_message = lambda do
      format_for_log(label, "#{time.round.to_i}ms", statement, bind_vars)
    end

    if time >= slowlog_threshold
      logger.warn(&generate_message)
    else
      logger.debug(&generate_message)
    end
  rescue Exception => e
    logger.error { format_for_log(label, 'ERROR', statement, bind_vars) }
    raise
  end
  response
end