Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ For activerecord instantiation counts only:

Rails.application.middleware.use( Oink::Middleware, :instruments => :activerecord )

Environment variables can also be logged by specifying `env_vars`. This is especially handy for displaying request ID or REQUEST_URI from the Rails `env` object.

Rails.application.middleware.use( Oink::Middleware, :env_vars => ['action_dispatch.request_id', 'REQUEST_ID'] )

Note that the previous way of configuring oink, as a set of modules to include into rails controllers, is deprecated.

== Analyzing logs
Expand Down
11 changes: 11 additions & 0 deletions lib/oink/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(app, options = {})
@app = app
@logger = options[:logger] || Hodel3000CompliantLogger.new("log/oink.log")
@instruments = options[:instruments] ? Array(options[:instruments]) : [:memory, :activerecord]
@env_vars = options[:env_vars] ? Array(options[:env_vars]) : []

Oink.extend_active_record! if @instruments.include?(:activerecord)
end
Expand All @@ -17,6 +18,7 @@ def call(env)
status, headers, body = @app.call(env)

log_routing(env)
log_environment(env)
log_memory
log_activerecord
log_completed
Expand All @@ -36,6 +38,15 @@ def log_routing(env)
end
end

def log_environment(env)
return if @env_vars.empty?
env_message = @env_vars.map { |key|
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.

value = env[key]
"#{key.inspect}: #{value.inspect if value && value.respond_to?(:inspect)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

}.join(', ')
@logger.info("Environment: {#{env_message}}")
end

def log_memory
if @instruments.include?(:memory)
memory = Oink::Instrumentation::MemorySnapshot.memory
Expand Down