Skip to content

Instantly share code, notes, and snippets.

@tomlea
Created December 18, 2009 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomlea/259510 to your computer and use it in GitHub Desktop.
Save tomlea/259510 to your computer and use it in GitHub Desktop.
module LongTransactionLogger
def transaction(options = {}, &block)
start_time = Time.now.to_f
rv = super(options, &block)
::LongTransactionLogger.log(Time.now.to_f - start_time, self.name, caller(1))
rv
end
def self.log(duration, model_name, stacktrace)
RAILS_DEFAULT_LOGGER.error "LongTransactionLogger (#{model_name}.transaction [#{duration}s]):\n#{stacktrace.join("\n")}" if duration > 5
end
def self.hook!
::ActiveRecord::Base.extend(self)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment