forked from brynary/rack-bug
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use of logging panel in plain Rack apps and handle inconsistenc…
…y between AS::BufferedLogger and Logger use amc-style to be consistent with other panels and for flexibility on swapping the logger out with a new instance, such as in tests. Do it without actual amc, though, to avoid AS dependency on non-Rails specific panel
- Loading branch information
Showing
4 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger | ||
module LoggerExtension | ||
def add(*args, &block) | ||
logged_message = super | ||
Rack::Bug::LogPanel.record(logged_message, args[0]) | ||
return logged_message | ||
end | ||
module Rack::Bug::LoggerExtension | ||
def self.included(target) | ||
target.send :alias_method, :add_without_rack_bug, :add | ||
target.send :alias_method, :add, :add_with_rack_bug | ||
end | ||
|
||
def add_with_rack_bug(*args, &block) | ||
logger_return = add_without_rack_bug(*args, &block) | ||
logged_message = logger_return | ||
logged_message = args[1] || args[2] unless logged_message.is_a?(String) | ||
Rack::Bug::LogPanel.record(logged_message, args[0]) | ||
return logger_return | ||
end | ||
end | ||
|
||
if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger | ||
logger = Rails.logger | ||
elsif defined?(LOGGER) | ||
logger = LOGGER | ||
end | ||
|
||
Rails.logger.extend LoggerExtensions | ||
if logger | ||
logger.class.send :include, Rack::Bug::LoggerExtension | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters