#new_rails_logger: custom logdev-template. Semlogger::Rack: #call will never super anymore.

This commit is contained in:
Denis Knauf 2012-11-21 16:11:34 +01:00
parent 25ff6d52d8
commit 6d2157caff
3 changed files with 30 additions and 13 deletions

View file

@ -1 +1 @@
0.0.9
0.0.10

View file

@ -72,9 +72,10 @@ class Semlogger < ::Logger
class <<self
attr_accessor :progname, :logger
def new_rails_logger config
def new_rails_logger config, logdev = nil
require 'semlogger/rack'
logdev = ::Rails.root.join( 'log', "#{::Rails.env.to_s.gsub('%', '%%')}.%Y-%m-%d.%$.log").to_s
logdev ||= ::Rails.root.join 'log', "#{::Rails.env.to_s.gsub('%', '%%')}.%Y-%m-%d.%$.log"
logdev = logdev.to_s
logger = nil
if Rails.env.production?
logger = new logdev
@ -106,11 +107,12 @@ class Semlogger < ::Logger
end
def tagged *tags, &e
@tags += tags
@tags += tags.flatten.compact
tags = tags.size
yield
ensure
tags.times { @tags.pop }
#tags.times { @tags.pop }
@tags.slice! -tags .. -1
end
def add severity, message = nil, progname = nil, &block

View file

@ -1,28 +1,43 @@
class Semlogger::Rack < Rails::Rack::Logger
def initialize app, tags = nil, data = nil
super app, tags
@data = data
@data = data || {}
end
def call_app request, env
path = request.filtered_path
Semlogger.custom( :connection, request.ip, Thread.current.object_id, request.request_method, path).info
Rails.logger.custom( :connection, request.ip, Thread.current.object_id, request.request_method, path).info
@app.call env
ensure
ActiveSupport::LogSubscriber.flush_all!
end
def call env
if @data
Rails.logger.data( compute_data( env)) { super env }
else
super env
end
end
def compute_data env
request = ActionDispatch::Request.new env
compute_tagged_ request do
compute_data_ request do
call_app request, env
end
end
end
def compute_tagged_ request
if Rails.logger.respond_to? :tagged
Rails.logger.tagged( compute_tags( request)) { yield }
else
yield
end
end
def compute_data_ request
if Rails.logger.respond_to? :data
Rails.logger.data( compute_data( request)) { yield }
else
yield
end
end
def compute_data request
data = @data.dup
data.each do |k, v|
case v