Class: ClickHouse::Middleware::Logging

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/click_house/middleware/logging.rb

Constant Summary collapse

EMPTY =
''
GET =
:get

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, logger:) ⇒ Logging

Returns a new instance of Logging.



13
14
15
16
# File 'lib/click_house/middleware/logging.rb', line 13

def initialize(app = nil, logger:)
  @logger = logger
  super(app)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/click_house/middleware/logging.rb', line 11

def logger
  @logger
end

#startingObject (readonly)

Returns the value of attribute starting.



11
12
13
# File 'lib/click_house/middleware/logging.rb', line 11

def starting
  @starting
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
# File 'lib/click_house/middleware/logging.rb', line 18

def call(env)
  @starting = timestamp
  super
end

#on_complete(env) ⇒ Object

rubocop:disable Layout/LineLength



24
25
26
27
28
29
# File 'lib/click_house/middleware/logging.rb', line 24

def on_complete(env)
  summary = SummaryMiddleware.extract(env)
  logger.info("\e[1mSQL (#{duration_stats_log(summary)})\e[0m #{query(env)};")
  logger.debug(env.request_body) if log_body?(env)
  logger.info("\e[1mRead: #{summary.read_rows} rows, #{summary.read_bytes_pretty}. Written: #{summary.written_rows} rows, #{summary.written_bytes_pretty}\e[0m")
end