slf4r 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/log4r_adapter.rb CHANGED
@@ -4,7 +4,7 @@ module Log4r
4
4
  def initialize(_fullname, _level=nil, _additive=true, _trace=false)
5
5
  @logger = ::Slf4r::LoggerFacade.new(_fullname)
6
6
  end
7
-
7
+
8
8
  def method_missing(method, *args, &block)
9
9
  @logger.send(method, *args, &block) if @logger.respond_to?(method)
10
10
  end
@@ -8,7 +8,7 @@ module Logging
8
8
  class << self
9
9
  alias :[] :new
10
10
  end
11
-
11
+
12
12
  def method_missing(method, *args, &block)
13
13
  @logger.send(method, *args, &block) if @logger.respond_to?(method)
14
14
  end
@@ -6,7 +6,7 @@ module Slf4r
6
6
  def format(exception)
7
7
  (": #{exception.message}:\n\t#{exception.backtrace.join("\n\t") if exception.backtrace }") if exception
8
8
  end
9
-
9
+
10
10
  def _debug(msg)
11
11
  raise NotImplementedError
12
12
  end
@@ -23,7 +23,11 @@ module Slf4r
23
23
  raise NotImplementedError
24
24
  end
25
25
 
26
- public
26
+ def _fatal(msg)
27
+ raise NotImplementedError
28
+ end
29
+
30
+ public
27
31
 
28
32
  attr_reader :name
29
33
 
@@ -36,8 +40,10 @@ module Slf4r
36
40
  end
37
41
 
38
42
  def debug(msg = nil, exception = nil)
39
- msg, exception = yield if block_given?
40
- _debug("#{msg}#{format(exception)}")
43
+ if(debug?)
44
+ msg, exception = yield if block_given?
45
+ _debug("#{msg}#{format(exception)}")
46
+ end
41
47
  end
42
48
 
43
49
  def info?
@@ -45,8 +51,10 @@ module Slf4r
45
51
  end
46
52
 
47
53
  def info(msg = nil, exception = nil)
48
- msg, exception = yield if block_given?
49
- _info("#{msg}#{format(exception)}")
54
+ if(info?)
55
+ msg, exception = yield if block_given?
56
+ _info("#{msg}#{format(exception)}")
57
+ end
50
58
  end
51
59
 
52
60
  def warn?
@@ -54,8 +62,10 @@ module Slf4r
54
62
  end
55
63
 
56
64
  def warn(msg = nil, exception = nil)
57
- msg, exception = yield if block_given?
58
- _warn("#{msg}#{format(exception)}")
65
+ if(warn?)
66
+ msg, exception = yield if block_given?
67
+ _warn("#{msg}#{format(exception)}")
68
+ end
59
69
  end
60
70
 
61
71
  def error?
@@ -63,8 +73,21 @@ module Slf4r
63
73
  end
64
74
 
65
75
  def error(msg = nil, exception = nil)
66
- msg, exception = yield if block_given?
67
- _error("#{msg}#{format(exception)}")
76
+ if(error?)
77
+ msg, exception = yield if block_given?
78
+ _error("#{msg}#{format(exception)}")
79
+ end
80
+ end
81
+
82
+ def fatal?
83
+ raise NotImplementedError
84
+ end
85
+
86
+ def fatal(msg = nil, exception = nil)
87
+ if(fatal?)
88
+ msg, exception = yield if block_given?
89
+ _fatal("#{msg}#{format(exception)}")
90
+ end
68
91
  end
69
92
  end
70
93
  end
@@ -13,13 +13,13 @@ module Slf4r
13
13
  attr_reader :name
14
14
 
15
15
  attr_reader :logger
16
-
16
+
17
17
  def initialize(name)
18
18
  @name = name
19
19
  @logger = org.slf4j.LoggerFactory.getLogger(name.to_s.sub(/^::/, '').gsub(/::/, '.'))
20
20
  end
21
21
 
22
- [:debug, :info, :warn, :error].each do |level|
22
+ [:debug, :info, :warn, :error, :fatal].each do |level|
23
23
  class_eval <<-CODE
24
24
  def #{level}?
25
25
  @logger.is_#{level}_enabled
@@ -27,7 +27,7 @@ module Slf4r
27
27
 
28
28
  def #{level}(msg = nil, exception = nil)
29
29
  if(@logger.is_#{level}_enabled)
30
- msg, exception = yield if block_given?
30
+ msg, exception = yield if block_given?
31
31
  if(exception.type == NativeException)
32
32
  @logger.#{level}(msg, exception.cause)
33
33
  else
@@ -3,18 +3,18 @@ require 'slf4r/abstract_logger_facade'
3
3
 
4
4
  module Slf4r
5
5
  class LoggerFacade < AbstractLoggerFacade
6
-
6
+
7
7
  attr_reader :logger
8
-
8
+
9
9
  def initialize(name)
10
10
  super
11
11
  @logger = ::Log4r::Logger::Repository[name] || ::Log4r::Logger.new(name)
12
12
  end
13
13
 
14
- public
14
+ public
15
15
 
16
16
  def debug?
17
- @logger.level == 0
17
+ @logger.level == Log4r::DEBUG
18
18
  end
19
19
 
20
20
  def _debug(msg)
@@ -22,7 +22,7 @@ module Slf4r
22
22
  end
23
23
 
24
24
  def info?
25
- @logger.level <= 1
25
+ @logger.level <= Log4r::INFO
26
26
  end
27
27
 
28
28
  def _info(msg)
@@ -30,7 +30,7 @@ module Slf4r
30
30
  end
31
31
 
32
32
  def warn?
33
- @logger.level <= 2
33
+ @logger.level <= Log4r::WARN
34
34
  end
35
35
 
36
36
  def _warn(msg)
@@ -38,12 +38,20 @@ module Slf4r
38
38
  end
39
39
 
40
40
  def error?
41
- @logger.level <= 3
41
+ @logger.level <= Log4r::ERROR
42
42
  end
43
43
 
44
44
  def _error(msg)
45
45
  @logger.error(msg)
46
46
  end
47
-
47
+
48
+ def fatal?
49
+ @logger.level <= Log4r::FATAL
50
+ end
51
+
52
+ def _fatal(msg)
53
+ @logger.fatal(msg)
54
+ end
55
+
48
56
  end
49
57
  end
@@ -3,9 +3,9 @@ require 'slf4r/abstract_logger_facade'
3
3
 
4
4
  module Slf4r
5
5
  class LoggerFacade < AbstractLoggerFacade
6
-
6
+
7
7
  attr_reader :logger
8
-
8
+
9
9
  def initialize(name)
10
10
  super
11
11
  log_name = nil
@@ -43,7 +43,11 @@ module Slf4r
43
43
  log(3, msg)
44
44
  end
45
45
 
46
- public
46
+ def _fatal(msg)
47
+ log(4, msg)
48
+ end
49
+
50
+ public
47
51
 
48
52
  def debug?
49
53
  @logger.level == 0
@@ -59,6 +63,10 @@ module Slf4r
59
63
 
60
64
  def error?
61
65
  @logger.level <= 3
62
- end
66
+ end
67
+
68
+ def fatal?
69
+ @logger.level <= 4
70
+ end
63
71
  end
64
72
  end
@@ -5,10 +5,10 @@ module Slf4r
5
5
  @name = name
6
6
  end
7
7
 
8
- public
8
+ public
9
9
 
10
10
  attr_reader :name
11
-
11
+
12
12
  def debug?
13
13
  false
14
14
  end
@@ -36,5 +36,12 @@ module Slf4r
36
36
 
37
37
  def error(msg = nil, exception = nil)
38
38
  end
39
+
40
+ def fatal?
41
+ false
42
+ end
43
+
44
+ def fatal(msg = nil, exception = nil)
45
+ end
39
46
  end
40
47
  end
@@ -3,7 +3,7 @@ require 'slf4r/abstract_logger_facade'
3
3
 
4
4
  module Slf4r
5
5
  class LoggerFacade4RubyLogger
6
-
6
+
7
7
  @@file = STDERR
8
8
  @@datetime_format = "%Y-%m-%d %H:%M:%S "
9
9
 
@@ -17,7 +17,7 @@ module Slf4r
17
17
  end
18
18
 
19
19
  def self.level=(level)
20
- @@level = level.instance_of?(Fixnum) ? level :
20
+ @@level = level.instance_of?(Fixnum) ? level :
21
21
  ::Logger.const_get(level.to_s.upcase)
22
22
  end
23
23
 
@@ -29,9 +29,9 @@ module Slf4r
29
29
  @@file = file
30
30
  end
31
31
  end
32
-
32
+
33
33
  class LoggerFacade < AbstractLoggerFacade
34
-
34
+
35
35
  def initialize(name)
36
36
  super
37
37
  @logger = LoggerFacade4RubyLogger.new_logger_facade(name)
@@ -61,7 +61,11 @@ module Slf4r
61
61
  log(::Logger::ERROR, msg)
62
62
  end
63
63
 
64
- public
64
+ def _fatal(msg)
65
+ log(::Logger::FATAL, msg)
66
+ end
67
+
68
+ public
65
69
 
66
70
  def debug?
67
71
  @logger.debug?
@@ -78,5 +82,9 @@ module Slf4r
78
82
  def error?
79
83
  @logger.error?
80
84
  end
85
+
86
+ def fatal?
87
+ @logger.fatal?
88
+ end
81
89
  end
82
90
  end
data/lib/slf4r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slf4r
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -39,7 +39,11 @@ module Slf4r
39
39
  @logger.error(msg)
40
40
  end
41
41
 
42
- public
42
+ def _fatal(msg)
43
+ @logger.fatal(msg)
44
+ end
45
+
46
+ public
43
47
 
44
48
  def debug?
45
49
  @logger.debug?
@@ -56,5 +60,9 @@ module Slf4r
56
60
  def error?
57
61
  @logger.error?
58
62
  end
63
+
64
+ def fatal?
65
+ @logger.fatal?
66
+ end
59
67
  end
60
68
  end
data/lib/slf4r.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'slf4r/logger'
2
2
  begin
3
3
  require 'slf4r/java_logger'
4
- rescue
4
+ rescue
5
5
  require 'slf4r/ruby_logger'
6
6
  end
@@ -45,7 +45,7 @@
45
45
  <input type="text" maxlength="128" name="search_theme_form" id="edit-search-theme-form-1" size="15" value="" title="Enter the terms you wish to search for." class="form-text" />
46
46
  </div>
47
47
  <input type="submit" name="op" id="edit-submit-3" value="Search" class="form-submit" />
48
- <input type="hidden" name="form_build_id" id="form-170ff38086b4f9c0f4a5721b05fc013c" value="form-170ff38086b4f9c0f4a5721b05fc013c" />
48
+ <input type="hidden" name="form_build_id" id="form-63b764693b5f6c8413114c00843ecb40" value="form-63b764693b5f6c8413114c00843ecb40" />
49
49
  <input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />
50
50
  </div>
51
51
 
@@ -89,7 +89,7 @@
89
89
  <input type="submit" name="op" id="edit-submit-2" value="Log in" class="form-submit" />
90
90
  <div class="item-list"><ul><li class="first"><a href="/user/register" title="Create a new user account.">Create new account</a></li>
91
91
  <li class="last"><a href="/user/password" title="Request new password via e-mail.">Request new password</a></li>
92
- </ul></div><input type="hidden" name="form_build_id" id="form-fa0c8fdd7cb8c41199a3f7de7460d66e" value="form-fa0c8fdd7cb8c41199a3f7de7460d66e" />
92
+ </ul></div><input type="hidden" name="form_build_id" id="form-9d23b46f847d1b7fffaee3248559c653" value="form-9d23b46f847d1b7fffaee3248559c653" />
93
93
  <input type="hidden" name="form_id" id="edit-user-login-block" value="user_login_block" />
94
94
 
95
95
  </div></form>
@@ -141,7 +141,7 @@ THE SOFTWARE.</p>
141
141
 
142
142
  <h2>Comment viewing options</h2>
143
143
 
144
- <div class="content"><div class="container-inline"><input type="hidden" name="form_build_id" id="form-10b484a00b7df2bbcad3d924d5376ac3" value="form-10b484a00b7df2bbcad3d924d5376ac3" />
144
+ <div class="content"><div class="container-inline"><input type="hidden" name="form_build_id" id="form-d05b982852a0332231c0915c07da1792" value="form-d05b982852a0332231c0915c07da1792" />
145
145
  <input type="hidden" name="form_id" id="edit-comment-controls" value="comment_controls" />
146
146
  <div class="form-item" id="edit-mode-wrapper">
147
147
  <select name="mode" class="form-select" id="edit-mode" ><option value="1">Flat list - collapsed</option><option value="2">Flat list - expanded</option><option value="3">Threaded list - collapsed</option><option value="4" selected="selected">Threaded list - expanded</option></select>
@@ -402,7 +402,7 @@ Martin M. Musatov</p>
402
402
 
403
403
  <h2>Comment viewing options</h2>
404
404
 
405
- <div class="content"><div class="container-inline"><input type="hidden" name="form_build_id" id="form-3e084c2c4b73ed012315ba6496924616" value="form-3e084c2c4b73ed012315ba6496924616" />
405
+ <div class="content"><div class="container-inline"><input type="hidden" name="form_build_id" id="form-812da949335437287350d654a2bb21c6" value="form-812da949335437287350d654a2bb21c6" />
406
406
  <input type="hidden" name="form_id" id="edit-comment-controls-1" value="comment_controls" />
407
407
  <div class="form-item" id="edit-mode-1-wrapper">
408
408
  <select name="mode" class="form-select" id="edit-mode-1" ><option value="1">Flat list - collapsed</option><option value="2">Flat list - expanded</option><option value="3">Threaded list - collapsed</option><option value="4" selected="selected">Threaded list - expanded</option></select>
@@ -12,7 +12,7 @@ require 'slf4r/log4r_logger'
12
12
 
13
13
  Log4r::Logger.root.level = Log4r::DEBUG
14
14
 
15
- out = Log4r::FileOutputter.new('logfile',
15
+ out = Log4r::FileOutputter.new('logfile',
16
16
  :filename => (basedir + 'tmp' + 'log4r.txt').to_s,
17
17
  :trunc=>false,
18
18
  :level => Log4r::DEBUG)
@@ -2,17 +2,17 @@ require 'pathname'
2
2
  require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
3
3
  def Slf4r.flush(klass)
4
4
  remove_const(klass.to_sym) if const_defined? klass.to_sym
5
- end
5
+ end
6
6
 
7
7
  def behave_as_logger(logger)
8
8
  filename = logger.name
9
9
  describe logger.name do
10
-
10
+
11
11
  it 'should have a name' do
12
12
  logger.name.should == filename
13
13
  logger.name.should_not be_nil
14
14
  end
15
-
15
+
16
16
  it 'should log into a file - no method args' do
17
17
  len1 = File2String.new("tmp/#{filename}.txt").length
18
18
  logger.debug()
@@ -28,7 +28,7 @@ def behave_as_logger(logger)
28
28
  len1 = File2String.new("tmp/#{filename}.txt").length
29
29
  len1.should > len2
30
30
  end
31
-
31
+
32
32
  it 'should log into a file - via block' do
33
33
  len1 = File2String.new("tmp/#{filename}.txt").length
34
34
  logger.debug{}
@@ -44,7 +44,7 @@ def behave_as_logger(logger)
44
44
  len1 = File2String.new("tmp/#{filename}.txt").length
45
45
  len1.should > len2
46
46
  end
47
-
47
+
48
48
  it 'should log into a file - exception' do
49
49
  exception = StandardError.new
50
50
  len1 = File2String.new("tmp/#{filename}.txt").length
@@ -61,6 +61,6 @@ def behave_as_logger(logger)
61
61
  len1 = File2String.new("tmp/#{filename}.txt").length
62
62
  len1.should > len2
63
63
  end
64
-
64
+
65
65
  end
66
66
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class File2String < String
2
-
2
+
3
3
  def initialize(file)
4
4
  content = ''
5
5
  f = File.open(file, "r")
@@ -7,7 +7,7 @@ load basedir + 'lib' + 'slf4r' + 'wrapped_logger.rb'
7
7
 
8
8
  logger = ::Logger.new(basedir + 'tmp' + 'wrapped.txt')
9
9
  logger.level == ::Logger::DEBUG
10
-
10
+
11
11
  Slf4r::LoggerFacade4WrappedLogger.logger = logger
12
12
 
13
13
  behave_as_logger(Slf4r::LoggerFacade.new('wrapped'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slf4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Meier
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-09 00:00:00 +05:30
12
+ date: 2010-05-12 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency