Permalink
Browse files

fix rails3 setup

  • Loading branch information...
mkristian committed Mar 1, 2011
1 parent cb2dc50 commit 974f621d71756d3d6cfdabd79a22294bf93995ee
Showing with 41 additions and 65 deletions.
  1. +0 −23 Manifest.txt
  2. +2 −1 lib/slf4r.rb
  3. +1 −0 lib/slf4r/abstract_logger_facade.rb
  4. +1 −1 lib/slf4r/logger.rb
  5. +2 −2 lib/slf4r/ruby_logger.rb
  6. +26 −29 lib/slf4r/slf4r_railtie.rb
  7. +1 −1 lib/slf4r/version.rb
  8. +4 −4 pom.xml
  9. +4 −4 slf4r.gemspec
View
@@ -1,23 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-lib/log4r_adapter.rb
-lib/logging_adapter.rb
-lib/ruby_logger_adapter.rb
-lib/slf4r.rb
-lib/slf4r/abstract_logger_facade.rb
-lib/slf4r/log4r_logger.rb
-lib/slf4r/logger.rb
-lib/slf4r/logging_logger.rb
-lib/slf4r/noop_logger.rb
-lib/slf4r/ruby_logger.rb
-lib/slf4r/version.rb
-lib/slf4r/wrapped_logger.rb
-spec/log4r_logger_spec.rb
-spec/logger_helper.rb
-spec/logging_logger_spec.rb
-spec/ruby_logger_spec.rb
-spec/spec.opts
-spec/spec_helper.rb
-spec/wrapper_logger_spec.rb
View
@@ -1,3 +1,4 @@
-if defined?(Rails)
+if defined?(Rails::Railtie)
require 'slf4r/slf4r_railtie'
end
+require 'slf4r/logger'
@@ -1,3 +1,4 @@
+require 'slf4r'
module Slf4r
class AbstractLoggerFacade
View
@@ -2,7 +2,7 @@ module Slf4r
module Logger
def logger
- @logger ||= LoggerFacade.new(self.class == Class ? name : self.class)
+ @logger ||= ::Slf4r::LoggerFacade.new(self.class == Class ? name : self.class)
end
end
View
@@ -10,7 +10,7 @@ class LoggerFacade4RubyLogger
def self.new_logger_facade(name)
@name = name
@logger = ::Logger.new(@@file)
- @@level = ::Logger::INFO unless self.class_variable_defined?(:@@level)
+ @@level = ::Logger::DEBUG unless self.class_variable_defined?(:@@level)
@logger.level = @@level
@logger.datetime_format = @@datetime_format
@logger
@@ -40,7 +40,7 @@ def initialize(name)
private
def log(type, msg)
- @logger.add(type, msg, @name)
+ @logger.add(type, "(#{@name}) " + msg, @name)
end
protected
View
@@ -1,41 +1,38 @@
class Slf4rRailtie < Rails::Railtie
- # config.before_configuration do |app|
- # app.config.class.class_eval do
- # attr_accessor :slf4r
- # end
- # end
-
- config.after_initialize do |app|
- if defined?(Slf4r)
- logger = (Rails.logger = setup_logger(Rails.logger, Rails))
- app.config.logger = setup_logger(app.config.logger, Rails.application.class)
- app.config.action_controller.logger = Slf4r::LoggerFacade.new(ActionController)
- app.config.active_record.logger = Slf4r::LoggerFacade.new(ActiveRecord)
- app.config.action_view.logger = Slf4r::LoggerFacade.new(ActionView)
- app.config.action_mailer.logger = Slf4r::LoggerFacade.new(ActionMailer)
- ActiveSupport::Cache::Store.logger = Slf4r::LoggerFacade.new(ActiveSupport::Cache::Store)
- clazz = if logger.instance_variable_get(:@logger).respond_to?(:java_class)
- logger.instance_variable_get(:@logger).java_class
+ config.before_configuration do |app|
+ #if defined?(Slf4r)
+ # require 'slf4r/ruby_logger' unless defined?(::Slf4r::LoggerFacade)
+ #end
+ if defined?(Slf4r::LoggerFacade)
+ @logger = (Rails.logger = setup_logger(Rails))
+ app.config.logger = @logger
+ 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=
+ app.config.action_mailer.logger = setup_logger(ActionMailer)
+ ActiveSupport::Cache::Store.logger = setup_logger(ActiveSupport::Cache::Store)
+ clazz = if @logger.instance_variable_get(:@logger).respond_to?(:java_class)
+ @logger.instance_variable_get(:@logger).java_class
else
- logger.instance_variable_get(:@logger).class
+ @logger.instance_variable_get(:@logger).class
end
- logger.info("setup slf4r logger categories for #{clazz}")
- else
+
+ end
+ end
+
+ config.after_initialize do |app|
+ unless defined?(Slf4r::LoggerFacade)
require 'slf4r/wrapped_logger'
- logger = (Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger)
- logger.info("setup slf4r logger wrapper with #{logger.class}")
+ Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger
+ puts "setup slf4r logger wrapper"
end
end
private
- def self.setup_logger(logger, category)
- l = Slf4r::LoggerFacade.new(category)
- real_logger = l.instance_variable_get(:@logger)
- # adjust log level it the logger implementation allows it
- if logger && real_logger.respond_to?(:level)
- real_logger.level = logger.level
- end
+ def self.setup_logger(category)
+ l = Slf4r::LoggerFacade.new((category == Rails ? "" : "Rails::") + category.to_s)
+ (@logger || l).info("setup logger for '#{l.name}")
l
end
end
View
@@ -1,3 +1,3 @@
module Slf4r
- VERSION = '0.4.0'.freeze
+ VERSION = '0.4.1'.freeze
end
View
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>rubygems</groupId>
<artifactId>slf4r</artifactId>
- <version>0.4.0</version>
+ <version>0.4.2-SNAPSHOT</version>
<packaging>gem</packaging>
<name>Slf4r</name>
<description>Slf4r provides a uniform interface for instantiating und using of a logger</description>
@@ -91,8 +91,8 @@
<version>${jruby.plugins.version}</version>
<extensions>true</extensions>
<configuration>
- <rdocOptions>--main, README.txt</rdocOptions>
- <extraRdocFiles>History.txt, README.txt</extraRdocFiles>
+ <rdocOptions>--main, README.rdoc</rdocOptions>
+ <extraRdocFiles>History.txt, README.rdoc</extraRdocFiles>
<extraFiles>Rakefile</extraFiles>
<gemspecOverwrite>true</gemspecOverwrite>
</configuration>
@@ -139,6 +139,6 @@
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <jruby.plugins.version>0.23.0-SNAPSHOT</jruby.plugins.version>
+ <jruby.plugins.version>0.24.0</jruby.plugins.version>
</properties>
</project>
View
@@ -1,7 +1,7 @@
# create by maven - leave it as is
Gem::Specification.new do |s|
s.name = 'slf4r'
- s.version = '0.4.0'
+ s.version = '0.4.1'
s.summary = 'Slf4r'
s.description = 'Slf4r provides a uniform interface for instantiating und using of a logger'
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
s.files = Dir['MIT-LICENSE']
s.licenses << 'MIT-LICENSE'
s.files += Dir['History.txt']
- s.files += Dir['README.txt']
- s.extra_rdoc_files = ['History.txt','README.txt']
+ s.files += Dir['README.rdoc']
+ s.extra_rdoc_files = ['History.txt','README.rdoc']
s.files += Dir['Rakefile']
- s.rdoc_options = ['--main','README.txt']
+ s.rdoc_options = ['--main','README.rdoc']
s.files += Dir['lib/**/*']
s.files += Dir['spec/**/*']
s.test_files += Dir['spec/**/*_spec.rb']

0 comments on commit 974f621

Please sign in to comment.