Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use Scrolls for logging

  • Loading branch information...
commit fe25528523b5f67bde2b78d8ac28cd69dea7b9b7 1 parent ab65457
@rwdaigle authored
View
1  Gemfile
@@ -11,6 +11,7 @@ gem 'dynamic_form'
gem 'wordnik'
gem 'queue_classic', '~> 2.0.0'
gem 'clockwork'
+gem 'scrolls'
gem 'haml'
gem 'jquery-rails'
View
1  Gemfile.lock
@@ -174,6 +174,7 @@ DEPENDENCIES
rails_log_stdout
rspec-rails
sass-rails
+ scrolls
uglifier
unicorn
will_paginate
View
1  config/initializers/scrolls.rb
@@ -0,0 +1 @@
+Scrolls::Log.start
View
44 lib/event_logging.rb
@@ -6,59 +6,17 @@ module EventLogger
module ClassMethods
- def hiya; puts "hiya"; end
-
def log(*segments, &block)
- ms = Benchmark.ms { yield } if block_given?
- log_data = default_log_data
call_log_data = segments.inject({}) do |map, segment|
map.merge!(segment.to_log)
end
- log_data.merge!(call_log_data)
- log_data.merge!(duration: ms.round(3)) if block_given?
- event_logger.info(log_data.to_json)
- end
-
- private
-
- def default_log_data
- { timestamp: Time.now.utc.to_f.round(5), source: source(2) }
- end
-
- def source(depth=1)
- caller_method = parse_caller(caller(depth+1).first).last
- klass = self.is_a?(Class) ? self.to_s : self.class.to_s
- "#{klass}##{caller_method}"
- end
-
- # Stolen from ActionMailer, where this was used but was not made reusable
- def parse_caller(at)
- if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
- file = Regexp.last_match[1]
- line = Regexp.last_match[2].to_i
- method = Regexp.last_match[3]
- [file, line, method]
- end
+ Scrolls.log(call_log_data, &block)
end
- def event_logger
- Rails.logger
- end
end
-
- # def log(*tokens, &block)
- # ms = Benchmark.ms { yield } if block_given?
- # token_str = tokens.collect do |token|
- # token.respond_to?(:to_log) ? token.to_log : token.to_s
- # end.join(' ')
- # execution = ms ? "execution=#{ms.round(3)}ms" : nil
- # klass = self.is_a?(Class) ? self : self.class
- # self.class.event_logger.info "[#{klass}] event=#{self.class.caller_method} #{token_str} #{execution}"
- # end
end
class Hash
-
def to_log
self
end
Please sign in to comment.
Something went wrong with that request. Please try again.