Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make logging more convenient

  • Loading branch information...
commit 0a0a9f74b0082c9b93277e1d243c5e6b316166ef 1 parent 9b44655
Ryan Daigle authored
Showing with 42 additions and 2 deletions.
  1. +1 −1  app/models/gist.rb
  2. +41 −1 config/initializers/logging.rb
2  app/models/gist.rb
View
@@ -42,7 +42,7 @@ def import(gh_gist)
end
def search(q)
- Scrolls.log(ns: self, fn: __method__, query: q) do
+ log(ns: self, fn: __method__, query: q) do
tire.search do
query { string q }
sort { by :gh_created_at, 'desc' }
42 config/initializers/logging.rb
View
@@ -3,5 +3,45 @@
logger.level = Logger.const_get(([ENV['LOG_LEVEL'].to_s.upcase, "INFO"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first)
Rails.logger = Rails.application.config.logger = logger
+# Scrolls for log output
Scrolls.global_context(app: "gisted", env: ENV["RAILS_ENV"])
-Scrolls.time_unit = "ms"
+Scrolls.time_unit = "ms"
+
+# Convenience log methods
+
+require 'active_support/concern'
+
+module EventLogger
+
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+
+ def log_context(*segments, &block)
+ Scrolls.context(log_data_from(*segments), &block)
+ end
+
+ def log(*segments, &block)
+ Scrolls.log(log_data_from(*segments), &block)
+ end
+
+ private
+
+ def log_data_from(*segments)
+ segments.inject({}) do |map, segment|
+ map.merge!(segment.to_log)
+ end
+ end
+
+ end
+end
+
+class Hash
+ def to_log
+ self
+ end
+end
+
+class Object
+ include EventLogger
+end
Please sign in to comment.
Something went wrong with that request. Please try again.