Semlogger.new_rails_logger(config) can be used in config/environment.rb for initialize Semlogger for Rails. Different behaviour for different environments.
This commit is contained in:
parent
eba19017af
commit
e04b61dd4a
|
@ -66,6 +66,25 @@ class Semlogger < ::Logger
|
||||||
attr_accessor :logdev, :level, :progname
|
attr_accessor :logdev, :level, :progname
|
||||||
class <<self
|
class <<self
|
||||||
attr_accessor :progname, :logger
|
attr_accessor :progname, :logger
|
||||||
|
|
||||||
|
def new_rails_logger config
|
||||||
|
require 'semlogger/rack'
|
||||||
|
logdev = ::Rails.root.join( 'log', "#{::Rails.env.to_s.gsub('%', '%%')}.%Y-%m-%d.%$.log")
|
||||||
|
logger = nil
|
||||||
|
if Rails.env.production?
|
||||||
|
logger.new logdev
|
||||||
|
logger.level = INFO
|
||||||
|
elsif Rails.env.development?
|
||||||
|
logger.new Semlogger::Multiplex.new( Semlogger::FInfo.new( Semlogger::Printer.new), Semlogger::Writer.new( logdev))
|
||||||
|
logger.level = DEBUG
|
||||||
|
else
|
||||||
|
logger.new logdev
|
||||||
|
logger.level = DEBUG
|
||||||
|
end
|
||||||
|
config.middleware.swap Rails::Rack::Logger, Semlogger::Rack, [], {reqid: :uuid}
|
||||||
|
config.logger = logger
|
||||||
|
end
|
||||||
|
|
||||||
def custom( *a) CustomType.new( *a).tap {|t| t.logger = self.logger } end
|
def custom( *a) CustomType.new( *a).tap {|t| t.logger = self.logger } end
|
||||||
end
|
end
|
||||||
def custom( *a) CustomType.new( *a).tap {|t| t.logger = self } end
|
def custom( *a) CustomType.new( *a).tap {|t| t.logger = self } end
|
||||||
|
|
Loading…
Reference in a new issue