Permalink
Browse files

Adding RackLog and DummyLog to simplify configuration

  • Loading branch information...
1 parent fd04c72 commit fb6c5ee149673554c987f43cbde78a05da219321 @brynary committed Aug 26, 2009
Showing with 32 additions and 1 deletion.
  1. +1 −0 init.rb
  2. +2 −0 lib/oink.rb
  3. +15 −0 lib/oink/dummy_log.rb
  4. +5 −1 lib/oink/log.rb
  5. +9 −0 lib/oink/rack_log.rb
View
1 init.rb
@@ -0,0 +1 @@
+require "oink"
View
2 lib/oink.rb
@@ -1,9 +1,11 @@
module Oink
+ autoload :DummyLog, "oink/dummy_log"
autoload :Formatter, "oink/formatter"
autoload :Log, "oink/log"
autoload :MethodTracker, "oink/method_tracker"
autoload :Metrics, "oink/metrics"
autoload :Middleware, "oink/middleware"
+ autoload :RackLog, "oink/rack_log"
def self.measure(name, &block)
result = nil
View
15 lib/oink/dummy_log.rb
@@ -0,0 +1,15 @@
+module Oink
+ class DummyLog
+
+ def metric(name)
+ end
+
+ def []=(key, value)
+ end
+
+ def transaction
+ yield
+ end
+
+ end
+end
View
6 lib/oink/log.rb
@@ -5,11 +5,15 @@ class Log
def initialize(logger, extra_metadata = [])
@logger = logger
- @metadata = %w[transaction date time] + extra_metadata
+ @metadata = default_metadata + extra_metadata
Metrics::Extensions.add_to(self)
write_headers
end
+ def default_metadata
+ %w[transaction date time]
+ end
+
def write_headers
write_header "Start-Date", Time.now.utc.strftime("%F %T")
write_header "Fields", (@metadata + metrics.map(&:field_names)).join(" ")
View
9 lib/oink/rack_log.rb
@@ -0,0 +1,9 @@
+module Oink
+ class RackLog < Log
+
+ def default_metadata
+ super + %w[controller_name action_name uri http_method response_code]
+ end
+
+ end
+end

0 comments on commit fb6c5ee

Please sign in to comment.