#new_rails_logger: custom logdev-template. Semlogger::Rack: #call will never super anymore.
This commit is contained in:
parent
25ff6d52d8
commit
6d2157caff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
request = ActionDispatch::Request.new env
|
||||
compute_tagged_ request do
|
||||
compute_data_ request do
|
||||
call_app request, env
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def compute_data env
|
||||
request = ActionDispatch::Request.new env
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue