Skip to content

Commit

Permalink
Merge pull request #86 from modosc/master
Browse files Browse the repository at this point in the history
use a frozen copy of Rails.root in AppNotifications and LogInterceptor
  • Loading branch information
dejan committed Dec 6, 2014
2 parents ef848e4 + 1e48ed5 commit 439c3cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions meta_request/lib/meta_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module MetaRequest
def self.logger
@@logger ||= Logger.new(File.join(Rails.root, 'log', 'meta_request.log'))
end

# stash a frozen copy away so we're not allocating a new string over and over
# again in AppNotifications and LogInterceptor
def self.rails_root
@@rails_root ||= Rails.root.to_s.freeze
end
end

require "meta_request/railtie"
2 changes: 1 addition & 1 deletion meta_request/lib/meta_request/app_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.subscribe
subscribe("meta_request.log").
subscribe("sql.active_record") do |*args|
name, start, ending, transaction_id, payload = args
dev_caller = caller.detect { |c| c=~/#{Rails.root}/ }
dev_caller = caller.detect { |c| c.include? MetaRequest.rails_root }
if dev_caller
c = Callsite.parse(dev_caller)
payload.merge!(:line => c.line, :filename => c.filename, :method => c.method)
Expand Down
6 changes: 3 additions & 3 deletions meta_request/lib/meta_request/log_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def unknown(message = nil, &block)
push_event(:unknown, message)
super
end


private
def push_event(level, message)
dev_log = AppRequest.current && caller[1] =~ /#{Rails.root}/
dev_log = AppRequest.current && caller[1].include?(MetaRequest.rails_root)
if dev_log
c = Callsite.parse(caller[1])
payload = {:message => message, :level => level, :line => c.line, :filename => c.filename, :method => c.method}
Expand Down

0 comments on commit 439c3cf

Please sign in to comment.