Class: Cequel::Metal::RequestLogger Private

Inherits:
Object
  • Object
show all
Extended by:
Util::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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Forwardable

delegate

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


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:

  • (::Logger)

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

Since:

  • 1.0.0


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:

  • (Integer)

    Only log queries that take longer than threshold ms

Since:

  • 1.0.0


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

def slowlog_threshold
  @slowlog_threshold
end

Instance Method Details

#log(label, statement) ⇒ 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:

  • label (String)

    a logical label for this statement

  • statement (String, Statement, Batch)

    the CQL statement to log

Since:

  • 1.0.0


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

def log(label, statement)
  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)
    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) }
    raise
  end
  response
end