Class: Cequel::Metal::RequestLogger Private
- Inherits:
-
Object
- Object
- Cequel::Metal::RequestLogger
- 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.
Instance Attribute Summary collapse
-
#logger ⇒ ::Logger
private
An instance of Logger that responds to methods for standard severity levels.
-
#slowlog_threshold ⇒ Integer
private
Only log queries that take longer than threshold ms.
Instance Method Summary collapse
-
#initialize ⇒ RequestLogger
constructor
private
A new instance of RequestLogger.
-
#log(label, statement) ⇒ void
private
Log a CQL statement.
Methods included from Util::Forwardable
Constructor Details
#initialize ⇒ RequestLogger
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.
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.
13 14 15 |
# File 'lib/cequel/metal/request_logger.rb', line 13 def logger @logger end |
#slowlog_threshold ⇒ Integer
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.
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
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 } = lambda do format_for_log(label, "#{time.round.to_i}ms", statement) end if time >= slowlog_threshold logger.warn(&) else logger.debug(&) end rescue Exception => e logger.error { format_for_log(label, 'ERROR', statement) } raise end response end |