Skip to content

Commit

Permalink
Adding RackLog and DummyLog to simplify configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Aug 26, 2009
1 parent fd04c72 commit fb6c5ee
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions init.rb
@@ -0,0 +1 @@
require "oink"
2 changes: 2 additions & 0 deletions 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
Expand Down
15 changes: 15 additions & 0 deletions 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
6 changes: 5 additions & 1 deletion lib/oink/log.rb
Expand Up @@ -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(" ")
Expand Down
9 changes: 9 additions & 0 deletions 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.