From 1e48ed5adac928698a331da944543d68d1c47ae8 Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Fri, 5 Dec 2014 16:43:23 -0800 Subject: [PATCH] use a frozen copy of Rails.root in AppNotifications and LogInterceptor --- meta_request/lib/meta_request.rb | 6 ++++++ meta_request/lib/meta_request/app_notifications.rb | 2 +- meta_request/lib/meta_request/log_interceptor.rb | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/meta_request/lib/meta_request.rb b/meta_request/lib/meta_request.rb index bff72b6..3a0c960 100644 --- a/meta_request/lib/meta_request.rb +++ b/meta_request/lib/meta_request.rb @@ -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" diff --git a/meta_request/lib/meta_request/app_notifications.rb b/meta_request/lib/meta_request/app_notifications.rb index 4b16c5c..ebc78f8 100644 --- a/meta_request/lib/meta_request/app_notifications.rb +++ b/meta_request/lib/meta_request/app_notifications.rb @@ -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) diff --git a/meta_request/lib/meta_request/log_interceptor.rb b/meta_request/lib/meta_request/log_interceptor.rb index c61aff5..7149af2 100644 --- a/meta_request/lib/meta_request/log_interceptor.rb +++ b/meta_request/lib/meta_request/log_interceptor.rb @@ -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}