slf4r 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,3 +1,4 @@
1
+ require 'slf4r'
1
2
  module Slf4r
2
3
  class AbstractLoggerFacade
3
4
 
data/lib/slf4r/logger.rb CHANGED
@@ -2,7 +2,7 @@ module Slf4r
2
2
  module Logger
3
3
 
4
4
  def logger
5
- @logger ||= LoggerFacade.new(self.class == Class ? name : self.class)
5
+ @logger ||= ::Slf4r::LoggerFacade.new(self.class == Class ? name : self.class)
6
6
  end
7
7
 
8
8
  end
@@ -10,7 +10,7 @@ module Slf4r
10
10
  def self.new_logger_facade(name)
11
11
  @name = name
12
12
  @logger = ::Logger.new(@@file)
13
- @@level = ::Logger::INFO unless self.class_variable_defined?(:@@level)
13
+ @@level = ::Logger::DEBUG unless self.class_variable_defined?(:@@level)
14
14
  @logger.level = @@level
15
15
  @logger.datetime_format = @@datetime_format
16
16
  @logger
@@ -40,7 +40,7 @@ module Slf4r
40
40
  private
41
41
 
42
42
  def log(type, msg)
43
- @logger.add(type, msg, @name)
43
+ @logger.add(type, "(#{@name}) " + msg, @name)
44
44
  end
45
45
 
46
46
  protected
@@ -1,41 +1,38 @@
1
1
  class Slf4rRailtie < Rails::Railtie
2
2
 
3
- # config.before_configuration do |app|
4
- # app.config.class.class_eval do
5
- # attr_accessor :slf4r
6
- # end
7
- # end
8
-
9
- config.after_initialize do |app|
10
- if defined?(Slf4r)
11
- logger = (Rails.logger = setup_logger(Rails.logger, Rails))
12
- app.config.logger = setup_logger(app.config.logger, Rails.application.class)
13
- app.config.action_controller.logger = Slf4r::LoggerFacade.new(ActionController)
14
- app.config.active_record.logger = Slf4r::LoggerFacade.new(ActiveRecord)
15
- app.config.action_view.logger = Slf4r::LoggerFacade.new(ActionView)
16
- app.config.action_mailer.logger = Slf4r::LoggerFacade.new(ActionMailer)
17
- ActiveSupport::Cache::Store.logger = Slf4r::LoggerFacade.new(ActiveSupport::Cache::Store)
18
- clazz = if logger.instance_variable_get(:@logger).respond_to?(:java_class)
19
- logger.instance_variable_get(:@logger).java_class
3
+ config.before_configuration do |app|
4
+ #if defined?(Slf4r)
5
+ # require 'slf4r/ruby_logger' unless defined?(::Slf4r::LoggerFacade)
6
+ #end
7
+ if defined?(Slf4r::LoggerFacade)
8
+ @logger = (Rails.logger = setup_logger(Rails))
9
+ app.config.logger = @logger
10
+ app.config.action_controller.logger = setup_logger(ActionController)
11
+ app.config.active_record.logger = setup_logger(ActiveRecord)
12
+ app.config.action_view.logger = setup_logger(ActionView) if app.config.action_view.respond_to? :logger=
13
+ app.config.action_mailer.logger = setup_logger(ActionMailer)
14
+ ActiveSupport::Cache::Store.logger = setup_logger(ActiveSupport::Cache::Store)
15
+ clazz = if @logger.instance_variable_get(:@logger).respond_to?(:java_class)
16
+ @logger.instance_variable_get(:@logger).java_class
20
17
  else
21
- logger.instance_variable_get(:@logger).class
18
+ @logger.instance_variable_get(:@logger).class
22
19
  end
23
- logger.info("setup slf4r logger categories for #{clazz}")
24
- else
20
+
21
+ end
22
+ end
23
+
24
+ config.after_initialize do |app|
25
+ unless defined?(Slf4r::LoggerFacade)
25
26
  require 'slf4r/wrapped_logger'
26
- logger = (Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger)
27
- logger.info("setup slf4r logger wrapper with #{logger.class}")
27
+ Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger
28
+ puts "setup slf4r logger wrapper"
28
29
  end
29
30
  end
30
31
 
31
32
  private
32
- def self.setup_logger(logger, category)
33
- l = Slf4r::LoggerFacade.new(category)
34
- real_logger = l.instance_variable_get(:@logger)
35
- # adjust log level it the logger implementation allows it
36
- if logger && real_logger.respond_to?(:level)
37
- real_logger.level = logger.level
38
- end
33
+ def self.setup_logger(category)
34
+ l = Slf4r::LoggerFacade.new((category == Rails ? "" : "Rails::") + category.to_s)
35
+ (@logger || l).info("setup logger for '#{l.name}")
39
36
  l
40
37
  end
41
38
  end
data/lib/slf4r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slf4r
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
data/lib/slf4r.rb CHANGED
@@ -1,3 +1,4 @@
1
- if defined?(Rails)
1
+ if defined?(Rails::Railtie)
2
2
  require 'slf4r/slf4r_railtie'
3
3
  end
4
+ require 'slf4r/logger'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Meier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-11 00:00:00 +05:30
17
+ date: 2011-03-01 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -96,11 +96,11 @@ extensions: []
96
96
 
97
97
  extra_rdoc_files:
98
98
  - History.txt
99
- - README.txt
99
+ - README.rdoc
100
100
  files:
101
101
  - MIT-LICENSE
102
102
  - History.txt
103
- - README.txt
103
+ - README.rdoc
104
104
  - Rakefile
105
105
  - lib/slf4r.rb
106
106
  - lib/logging_adapter.rb
@@ -138,7 +138,7 @@ licenses:
138
138
  post_install_message:
139
139
  rdoc_options:
140
140
  - --main
141
- - README.txt
141
+ - README.rdoc
142
142
  require_paths:
143
143
  - lib
144
144
  required_ruby_version: !ruby/object:Gem::Requirement