Permalink
Browse files

hope that works with servlet and normal setup

  • Loading branch information...
1 parent ab86e11 commit 1f08289fb09d19847d508521e9b2895711664c27 @mkristian committed Mar 18, 2011
@@ -5,15 +5,14 @@ def setup
source = File.expand_path('../../templates', __FILE__)
initializer "log4j.rb", File.read(File.join(source, "log4j.rb"))
initializer "log4j.properties", File.read(File.join(source, "log4j.properties"))
+ gem 'slf4r', :require => 'slf4r/java_logger'
- gemfile = File.read('Gemfile')
+ file_name = 'Mavenfile'
jar_line = "org.slf4j.slf4j-log4j12"
- unless gemfile =~ /#{jar_line}/
- File.open('Gemfile', 'a') do |f|
- f.puts
- f.puts "if defined? MAVEN"
- f.puts " jar '#{jar_line}', '1.6.1'"
- f.puts "end"
+ mavenfile = File.exists?(file_name) ? File.read(file_name) : ''
+ unless mavenfile =~ /#{jar_line}/
+ File.open(file_name, 'a') do |f|
+ f.puts "jar '#{jar_line}', '1.6.1'"
end
end
end
@@ -4,6 +4,7 @@ class Slf4r::LoggingGenerator < Rails::Generators::Base
def setup
source = File.expand_path('../../templates', __FILE__)
initializer "logging.rb", File.read(File.join(source, "logging.rb"))
+ gem 'slf4r', :require => 'slf4r/logging_logger'
gem "logging"
end
end
View
@@ -2,8 +2,13 @@ class Slf4rRailtie < Rails::Railtie
initializer "set_servlet_logger", :after => :initialize_logger do |app|
if defined?(Slf4r::LoggerFacade)
- @logger = (Rails.logger = setup_logger(Rails))
- app.config.logger = @logger
+ @logger = Slf4r::LoggerFacade.new("Rails::Setup")
+ @logger.info {
+ l = @logger.instance_variable_get('@logger'.to_sym)
+ logger_name = l.respond_to?(:java_class) ? l.java_class : l.class
+ "setup slf4r logger #{logger_name}"
+ }
+ app.config.logger = Rails.logger = setup_logger(Rails)
app.config.action_controller.logger = setup_logger(ActionController)
app.config.active_record.logger = setup_logger(ActiveRecord)
app.config.action_view.logger = setup_logger(ActionView) if app.config.action_view.respond_to? :logger=
@@ -16,15 +21,15 @@ class Slf4rRailtie < Rails::Railtie
end
else
require 'slf4r/wrapped_logger'
- Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger
- puts "setup slf4r logger wrapper"
+ l = Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger
+ l.info "setup slf4r logger wrapper"
end
end
private
def self.setup_logger(category)
l = Slf4r::LoggerFacade.new((category == Rails ? "" : "Rails::") + category.to_s)
- (@logger || l).info("setup logger for '#{l.name}")
+ @logger.info("setup logger for '#{l.name}'") if @logger
l
end
end

0 comments on commit 1f08289

Please sign in to comment.