Sha256: 9b70c57d78f25f418f5e997bda13c0b7322e1f5b53fb3eee76b2c7c75f416969
Contents?: true
Size: 1.05 KB
Versions: 15
Compression:
Stored size: 1.05 KB
Contents
module DataMapper module Railties class LogSubscriber < ActiveSupport::LogSubscriber def self.runtime=(value) Thread.current["data_mapper_sql_runtime"] = value end def self.runtime Thread.current["data_mapper_sql_runtime"] ||= 0 end def self.reset_runtime rt, self.runtime = runtime, 0 rt end def initialize super @odd_or_even = false end def sql(event) self.class.runtime += event.duration return unless logger.debug? name = '%s (%.3fms)' % [event.payload[:name], event.duration] sql = event.payload[:sql].squeeze(' ') if odd? name = color(name, CYAN, true) sql = color(sql, nil, true) else name = color(name, MAGENTA, true) end debug " #{name} #{sql}" end def odd? @odd_or_even = !@odd_or_even end def logger ::DataMapper.logger end end end end DataMapper::Railties::LogSubscriber.attach_to :data_mapper
Version data entries
15 entries across 15 versions & 3 rubygems