logging 1.8.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/History.txt +20 -0
  4. data/README.md +159 -0
  5. data/Rakefile +9 -5
  6. data/examples/appenders.rb +0 -4
  7. data/examples/layouts.rb +1 -8
  8. data/examples/names.rb +4 -4
  9. data/lib/logging.rb +24 -76
  10. data/lib/logging/appender.rb +71 -16
  11. data/lib/logging/appenders.rb +0 -2
  12. data/lib/logging/appenders/buffering.rb +32 -16
  13. data/lib/logging/appenders/file.rb +2 -2
  14. data/lib/logging/appenders/io.rb +1 -1
  15. data/lib/logging/appenders/rolling_file.rb +228 -165
  16. data/lib/logging/appenders/string_io.rb +1 -1
  17. data/lib/logging/appenders/syslog.rb +4 -4
  18. data/lib/logging/color_scheme.rb +20 -3
  19. data/lib/logging/diagnostic_context.rb +142 -17
  20. data/lib/logging/filter.rb +18 -0
  21. data/lib/logging/filters.rb +4 -0
  22. data/lib/logging/filters/level.rb +29 -0
  23. data/lib/logging/layout.rb +2 -2
  24. data/lib/logging/layouts/parseable.rb +5 -2
  25. data/lib/logging/layouts/pattern.rb +309 -168
  26. data/lib/logging/log_event.rb +5 -5
  27. data/lib/logging/logger.rb +55 -68
  28. data/lib/logging/repository.rb +24 -39
  29. data/lib/logging/root_logger.rb +1 -1
  30. data/lib/logging/utils.rb +4 -65
  31. data/lib/logging/version.rb +8 -0
  32. data/lib/rspec/logging_helper.rb +3 -3
  33. data/logging.gemspec +46 -0
  34. data/test/appenders/test_buffered_io.rb +29 -0
  35. data/test/appenders/test_file.rb +2 -2
  36. data/test/appenders/test_rolling_file.rb +62 -1
  37. data/test/layouts/test_color_pattern.rb +1 -1
  38. data/test/layouts/test_json.rb +3 -0
  39. data/test/layouts/test_pattern.rb +6 -2
  40. data/test/layouts/test_yaml.rb +4 -1
  41. data/test/test_appender.rb +56 -0
  42. data/test/test_filter.rb +33 -0
  43. data/test/test_layout.rb +4 -8
  44. data/test/test_log_event.rb +3 -3
  45. data/test/test_logger.rb +81 -57
  46. data/test/test_logging.rb +0 -59
  47. data/test/test_mapped_diagnostic_context.rb +49 -1
  48. data/test/test_nested_diagnostic_context.rb +16 -1
  49. data/test/test_repository.rb +24 -32
  50. data/test/test_utils.rb +14 -50
  51. metadata +35 -53
  52. data/README.rdoc +0 -143
  53. data/data/bad_logging_1.rb +0 -13
  54. data/data/bad_logging_2.rb +0 -21
  55. data/data/logging.rb +0 -42
  56. data/data/logging.yaml +0 -63
  57. data/data/simple_logging.rb +0 -13
  58. data/examples/consolidation.rb +0 -83
  59. data/lib/logging/appenders/email.rb +0 -178
  60. data/lib/logging/appenders/growl.rb +0 -200
  61. data/lib/logging/config/configurator.rb +0 -187
  62. data/lib/logging/config/yaml_configurator.rb +0 -190
  63. data/lib/logging/stats.rb +0 -277
  64. data/test/appenders/test_email.rb +0 -170
  65. data/test/appenders/test_growl.rb +0 -138
  66. data/test/config/test_configurator.rb +0 -69
  67. data/test/config/test_yaml_configurator.rb +0 -39
  68. data/test/test_consolidate.rb +0 -45
  69. data/test/test_stats.rb +0 -273
  70. data/version.txt +0 -1
@@ -7,9 +7,9 @@ module RSpec
7
7
  # supports a readline method to access the log messages.
8
8
  #
9
9
  def capture_log_messages( opts = {} )
10
- from = opts.getopt(:from, 'root')
11
- to = opts.getopt(:to, '__rspec__')
12
- exclusive = opts.getopt(:exclusive, true)
10
+ from = opts.fetch(:from, 'root')
11
+ to = opts.fetch(:to, '__rspec__')
12
+ exclusive = opts.fetch(:exclusive, true)
13
13
 
14
14
  appender = Logging::Appenders[to] || Logging::Appenders::StringIo.new(to)
15
15
  logger = Logging::Logger[from]
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: logging 2.0.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "logging"
6
+ s.version = "2.0.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Tim Pease"]
11
+ s.date = "2015-03-29"
12
+ s.description = "Logging is a flexible logging library for use in Ruby programs based on the\ndesign of Java's log4j library. It features a hierarchical logging system,\ncustom level names, multiple output destinations per log event, custom\nformatting, and more."
13
+ s.email = "tim.pease@gmail.com"
14
+ s.extra_rdoc_files = ["History.txt"]
15
+ s.files = [".gitignore", ".travis.yml", "History.txt", "README.md", "Rakefile", "examples/appenders.rb", "examples/classes.rb", "examples/colorization.rb", "examples/custom_log_levels.rb", "examples/fork.rb", "examples/formatting.rb", "examples/hierarchies.rb", "examples/layouts.rb", "examples/lazy.rb", "examples/loggers.rb", "examples/mdc.rb", "examples/names.rb", "examples/rspec_integration.rb", "examples/simple.rb", "lib/logging.rb", "lib/logging/appender.rb", "lib/logging/appenders.rb", "lib/logging/appenders/buffering.rb", "lib/logging/appenders/console.rb", "lib/logging/appenders/file.rb", "lib/logging/appenders/io.rb", "lib/logging/appenders/rolling_file.rb", "lib/logging/appenders/string_io.rb", "lib/logging/appenders/syslog.rb", "lib/logging/color_scheme.rb", "lib/logging/diagnostic_context.rb", "lib/logging/filter.rb", "lib/logging/filters.rb", "lib/logging/filters/level.rb", "lib/logging/layout.rb", "lib/logging/layouts.rb", "lib/logging/layouts/basic.rb", "lib/logging/layouts/parseable.rb", "lib/logging/layouts/pattern.rb", "lib/logging/log_event.rb", "lib/logging/logger.rb", "lib/logging/proxy.rb", "lib/logging/rails_compat.rb", "lib/logging/repository.rb", "lib/logging/root_logger.rb", "lib/logging/utils.rb", "lib/logging/version.rb", "lib/rspec/logging_helper.rb", "lib/spec/logging_helper.rb", "logging.gemspec", "script/bootstrap", "test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_file.rb", "test/appenders/test_io.rb", "test/appenders/test_periodic_flushing.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_string_io.rb", "test/appenders/test_syslog.rb", "test/benchmark.rb", "test/layouts/test_basic.rb", "test/layouts/test_color_pattern.rb", "test/layouts/test_json.rb", "test/layouts/test_pattern.rb", "test/layouts/test_yaml.rb", "test/setup.rb", "test/test_appender.rb", "test/test_color_scheme.rb", "test/test_filter.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_mapped_diagnostic_context.rb", "test/test_nested_diagnostic_context.rb", "test/test_proxy.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_utils.rb"]
16
+ s.homepage = "http://rubygems.org/gems/logging"
17
+ s.rdoc_options = ["--main", "README.md"]
18
+ s.rubyforge_project = "logging"
19
+ s.rubygems_version = "2.2.2"
20
+ s.summary = "A flexible and extendable logging library for Ruby"
21
+ s.test_files = ["test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_file.rb", "test/appenders/test_io.rb", "test/appenders/test_periodic_flushing.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_string_io.rb", "test/appenders/test_syslog.rb", "test/layouts/test_basic.rb", "test/layouts/test_color_pattern.rb", "test/layouts/test_json.rb", "test/layouts/test_pattern.rb", "test/layouts/test_yaml.rb", "test/test_appender.rb", "test/test_color_scheme.rb", "test/test_filter.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_mapped_diagnostic_context.rb", "test/test_nested_diagnostic_context.rb", "test/test_proxy.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_utils.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 4
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<little-plugger>, ["~> 1.1"])
28
+ s.add_runtime_dependency(%q<multi_json>, ["~> 1.10"])
29
+ s.add_development_dependency(%q<flexmock>, ["~> 1.0"])
30
+ s.add_development_dependency(%q<bones-git>, ["~> 1.3"])
31
+ s.add_development_dependency(%q<bones>, [">= 3.8.3"])
32
+ else
33
+ s.add_dependency(%q<little-plugger>, ["~> 1.1"])
34
+ s.add_dependency(%q<multi_json>, ["~> 1.10"])
35
+ s.add_dependency(%q<flexmock>, ["~> 1.0"])
36
+ s.add_dependency(%q<bones-git>, ["~> 1.3"])
37
+ s.add_dependency(%q<bones>, [">= 3.8.3"])
38
+ end
39
+ else
40
+ s.add_dependency(%q<little-plugger>, ["~> 1.1"])
41
+ s.add_dependency(%q<multi_json>, ["~> 1.10"])
42
+ s.add_dependency(%q<flexmock>, ["~> 1.0"])
43
+ s.add_dependency(%q<bones-git>, ["~> 1.3"])
44
+ s.add_dependency(%q<bones>, [">= 3.8.3"])
45
+ end
46
+ end
@@ -41,6 +41,26 @@ module TestAppenders
41
41
  assert_raise(RuntimeError) {@appender.append event}
42
42
  end
43
43
 
44
+ def test_append_with_write_size
45
+ event = Logging::LogEvent.new('TestLogger', @levels['warn'], %w[a b c d], false)
46
+ @appender.write_size = 2
47
+
48
+ @appender.append event
49
+ assert_nil(readline)
50
+
51
+ @appender.append event
52
+ assert_nil(readline)
53
+
54
+ event.level = @levels['debug']
55
+ event.data = 'the big log message'
56
+ @appender.append event
57
+
58
+ assert_equal " WARN TestLogger : <Array> #{%w[a b c d]}\n", readline
59
+ assert_equal " WARN TestLogger : <Array> #{%w[a b c d]}\n", readline
60
+ assert_equal "DEBUG TestLogger : the big log message\n", readline
61
+ assert_nil(readline)
62
+ end
63
+
44
64
  def test_append_error
45
65
  # setup an internal logger to capture error messages from the IO
46
66
  # appender
@@ -147,6 +167,15 @@ module TestAppenders
147
167
  assert_nil(readline)
148
168
  end
149
169
 
170
+ def test_clear
171
+ @appender << "this is a test message\n"
172
+ @appender << "this is another test message\n"
173
+
174
+ @appender.clear!
175
+ @appender.flush
176
+ assert_nil(readline)
177
+ end
178
+
150
179
  def test_immediate_at
151
180
  event = Logging::LogEvent.new('TestLogger', @levels['warn'],
152
181
  [1, 2, 3, 4], false)
@@ -42,7 +42,7 @@ module TestAppenders
42
42
 
43
43
  def test_initialize
44
44
  log = File.join(TMP, 'file.log')
45
- appender = Logging.appenders.file(NAME, 'filename' => log)
45
+ appender = Logging.appenders.file(NAME, :filename => log)
46
46
  assert_equal 'logfile', appender.name
47
47
  assert_equal ::File.expand_path(log), appender.filename
48
48
  appender << "This will be the first line\n"
@@ -82,7 +82,7 @@ module TestAppenders
82
82
 
83
83
  def test_changing_directories
84
84
  log = File.join(TMP, 'file.log')
85
- appender = Logging.appenders.file(NAME, 'filename' => log)
85
+ appender = Logging.appenders.file(NAME, :filename => log)
86
86
 
87
87
  assert_equal 'logfile', appender.name
88
88
  assert_equal ::File.expand_path(log), appender.filename
@@ -111,7 +111,7 @@ module TestAppenders
111
111
  Dir.glob(d_glob).each {|fn| ::File.delete fn}
112
112
  cleanup
113
113
 
114
- ap = Logging.appenders.rolling_file(NAME, :filename => @fn, 'age' => 'daily')
114
+ ap = Logging.appenders.rolling_file(NAME, :filename => @fn, :age => 'daily')
115
115
  ap << "random message\n"
116
116
  assert_equal 1, Dir.glob(@glob).length
117
117
 
@@ -242,6 +242,67 @@ module TestAppenders
242
242
  cleanup
243
243
  end
244
244
 
245
+ def test_custom_numberd_filename
246
+ fn = File.expand_path('test.log{{.%d}}', TMP)
247
+ filename = File.expand_path('test.log', TMP)
248
+ glob = File.expand_path('test.log.*', TMP)
249
+
250
+ assert_equal [], Dir.glob(glob)
251
+ ap = Logging.appenders.rolling_file(NAME, :filename => fn, :size => 100, :keep => 2)
252
+
253
+ ap << 'X' * 100; ap.flush
254
+ assert_equal 0, Dir.glob(glob).length
255
+ assert_equal 100, File.size(filename)
256
+
257
+ # this character is appended to the log file (bringing its size to 101)
258
+ # and THEN the file is rolled resulting in a new, empty log file
259
+ ap << 'X'
260
+ assert_equal 1, Dir.glob(glob).length
261
+ assert_equal 0, File.size(filename)
262
+
263
+ ap << 'Y' * 100; ap.flush
264
+ assert_equal 1, Dir.glob(glob).length
265
+ assert_equal 100, File.size(filename)
266
+
267
+ ap << 'Y'
268
+ assert_equal 2, Dir.glob(glob).length
269
+ assert_equal 0, File.size(filename)
270
+
271
+ # now make sure we prune the correct file
272
+ ap << 'Z' * 101; ap.flush
273
+ files = Dir.glob(glob).sort
274
+ assert_equal 2, files.length
275
+ assert_equal 'Z'*101, ::File.read(files.first)
276
+ assert_equal 'Y'*101, ::File.read(files.last)
277
+
278
+ cleanup
279
+ end
280
+
281
+ def test_custom_timestamp_filename
282
+ fn = File.expand_path('test{{.%S:%M}}.log', TMP)
283
+ filename = File.expand_path('test.log', TMP)
284
+ age_file = filename + '.age'
285
+ glob = File.expand_path('test.*.log', TMP)
286
+
287
+ assert_equal [], Dir.glob(glob)
288
+ ap = Logging.appenders.rolling_file(NAME, :filename => fn, :age => 1, :keep => 2)
289
+
290
+ ap << "random message\n"
291
+ assert_equal 0, Dir.glob(glob).length
292
+
293
+ now = ::File.mtime(age_file)
294
+ start = now - 42
295
+ ::File.utime(start, start, age_file)
296
+ ap.instance_variable_set(:@age_fn_mtime, nil)
297
+ ap << "another random message\n"
298
+
299
+ files = Dir.glob(glob)
300
+ assert_equal 1, files.length
301
+ assert_match %r/test\.\d{2}:\d{2}\.log\z/, files.first
302
+
303
+ cleanup
304
+ end
305
+
245
306
  private
246
307
  def cleanup
247
308
  unless Logging.appenders[NAME].nil?
@@ -77,7 +77,7 @@ module TestLayouts
77
77
  event = Logging::LogEvent.new('ArrayLogger', @levels['info'], 'log message', false)
78
78
 
79
79
  rgxp = Regexp.new(
80
- '^\['+Regexp.escape(CS::BLUE)+'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'+Regexp.escape(CS::RESET)+
80
+ '^\['+Regexp.escape(CS::BLUE)+'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'+Regexp.escape(CS::RESET)+
81
81
  '\] INFO -- '+Regexp.escape(CS::GREEN)+'ArrayLogger'+Regexp.escape(CS::RESET)+
82
82
  ' : '+Regexp.escape(CS::MAGENTA)+'log message'+Regexp.escape(CS::RESET)
83
83
  )
@@ -98,6 +98,9 @@ module TestLayouts
98
98
  @layout.items = %w[method]
99
99
  assert_equal %Q[{"method":"method_name"}\n], @layout.format(event)
100
100
 
101
+ @layout.items = %w[hostname]
102
+ assert_equal %Q[{"hostname":"#{Socket.gethostname}"}\n], @layout.format(event)
103
+
101
104
  @layout.items = %w[pid]
102
105
  assert_match %r/\A\{"pid":\d+\}\n\z/, @layout.format(event)
103
106
 
@@ -11,7 +11,7 @@ module TestLayouts
11
11
  super
12
12
  @layout = Logging.layouts.pattern({})
13
13
  @levels = Logging::LEVELS
14
- @date_fmt = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
14
+ @date_fmt = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}'
15
15
  Thread.current[:name] = nil
16
16
  end
17
17
 
@@ -42,7 +42,7 @@ module TestLayouts
42
42
  end
43
43
 
44
44
  def test_date_pattern
45
- assert_equal '%Y-%m-%d %H:%M:%S', @layout.date_pattern
45
+ assert_equal '%Y-%m-%dT%H:%M:%S', @layout.date_pattern
46
46
  end
47
47
 
48
48
  def test_date_pattern_eq
@@ -142,6 +142,10 @@ module TestLayouts
142
142
  Thread.current[:name] = "Main"
143
143
  assert_equal "Main", @layout.format(event)
144
144
 
145
+ @layout.pattern = '%h'
146
+ hostname = Socket.gethostname
147
+ assert_equal hostname, @layout.format(event)
148
+
145
149
  @layout.pattern = '%%'
146
150
  assert_equal '%', @layout.format(event)
147
151
 
@@ -1,4 +1,4 @@
1
-
1
+ require 'time'
2
2
  require File.expand_path('../setup', File.dirname(__FILE__))
3
3
 
4
4
  module TestLogging
@@ -88,6 +88,9 @@ module TestLayouts
88
88
  @layout.items = %w[method]
89
89
  assert_match %r/\A--- ?\nmethod: method_name\n/, @layout.format(event)
90
90
 
91
+ @layout.items = %w[hostname]
92
+ assert_match %r/\A--- ?\nhostname: #{Socket.gethostname}\n/, @layout.format(event)
93
+
91
94
  @layout.items = %w[pid]
92
95
  assert_match %r/\A--- ?\npid: \d+\n\z/, @layout.format(event)
93
96
 
@@ -40,6 +40,54 @@ module TestLogging
40
40
  assert_raise(RuntimeError) {@appender.append @event}
41
41
  end
42
42
 
43
+ def test_append_with_filter
44
+ ary = []
45
+ @appender.instance_variable_set :@ary, ary
46
+ def @appender.write(event)
47
+ @ary << event
48
+ end
49
+ @appender.level = :debug
50
+
51
+ # Excluded
52
+ @appender.filters = ::Logging::Filters::Level.new :info
53
+ @appender.append @event
54
+ assert_nil ary.pop
55
+
56
+ # Allowed
57
+ @appender.filters = ::Logging::Filters::Level.new :debug
58
+ @appender.append @event
59
+ assert_equal @event, ary.pop
60
+
61
+ # No filter
62
+ @appender.filters = nil
63
+ @appender.append @event
64
+ assert_equal @event, ary.pop
65
+ end
66
+
67
+ def test_append_with_modifying_filter
68
+ ary = []
69
+ @appender.instance_variable_set :@ary, ary
70
+ def @appender.write(event)
71
+ @ary << event
72
+ end
73
+ @appender.level = :debug
74
+ @appender.filters = [
75
+ ::Logging::Filters::Level.new(:debug, :info),
76
+ RedactFilter.new
77
+ ]
78
+
79
+ # data will be redacted
80
+ @appender.append @event
81
+ event = ary.pop
82
+ assert_not_same @event, event
83
+ assert_equal "REDACTED!", event.data
84
+
85
+ # event will be filtered out
86
+ @event.level = @levels['warn']
87
+ @appender.append @event
88
+ assert_nil ary.pop
89
+ end
90
+
43
91
  def test_close
44
92
  assert_equal false, @appender.closed?
45
93
 
@@ -149,3 +197,11 @@ module TestLogging
149
197
  end # class TestAppender
150
198
  end # module TestLogging
151
199
 
200
+ class RedactFilter < ::Logging::Filter
201
+ def allow( event )
202
+ event = event.dup
203
+ event.data = "REDACTED!"
204
+ event
205
+ end
206
+ end
207
+
@@ -0,0 +1,33 @@
1
+ require File.expand_path('setup', File.dirname(__FILE__))
2
+
3
+ module TestLogging
4
+
5
+ class TestFilter < Test::Unit::TestCase
6
+ include LoggingTestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ ::Logging::init
12
+ @lf = ::Logging::Filters::Level.new :debug, :warn
13
+ end
14
+
15
+ def test_level_filter_includes_selected_level
16
+ debug_evt = event_for_level(:debug)
17
+ warn_evt = event_for_level(:warn)
18
+ assert_same debug_evt, @lf.allow(debug_evt), "Debug messages should be allowed"
19
+ assert_same warn_evt, @lf.allow(warn_evt), "Warn messages should be allowed"
20
+ end
21
+
22
+ def test_level_filter_excludes_unselected_level
23
+ event = event_for_level(:info)
24
+ assert_nil @lf.allow(event), "Info messages should be disallowed"
25
+ end
26
+
27
+ def event_for_level(level)
28
+ ::Logging::LogEvent.new('logger', ::Logging::LEVELS[level.to_s],
29
+ 'message', false)
30
+ end
31
+
32
+ end
33
+ end
@@ -20,16 +20,16 @@ module TestLogging
20
20
 
21
21
  assert_equal :string, obj_format[@layout]
22
22
 
23
- @layout = ::Logging::Layout.new 'format_as' => 'blah'
23
+ @layout = ::Logging::Layout.new :format_as => 'blah'
24
24
  assert_equal :string, obj_format[@layout]
25
25
 
26
26
  @layout = ::Logging::Layout.new :format_as => :inspect
27
27
  assert_equal :inspect, obj_format[@layout]
28
28
 
29
- @layout = ::Logging::Layout.new 'format_as' => :json
29
+ @layout = ::Logging::Layout.new :format_as => :json
30
30
  assert_equal :json, obj_format[@layout]
31
31
 
32
- @layout = ::Logging::Layout.new 'format_as' => :yaml
32
+ @layout = ::Logging::Layout.new :format_as => :yaml
33
33
  assert_equal :yaml, obj_format[@layout]
34
34
 
35
35
  @layout = ::Logging::Layout.new
@@ -85,11 +85,7 @@ module TestLogging
85
85
  assert_match %r/\A<Array> \n--- ?\n- one\n- two\n- three\n- four\n/, r
86
86
 
87
87
  r = @layout.format_obj Class
88
- if defined? YAML::ENGINE and YAML::ENGINE.yamler == 'psych'
89
- assert_equal "<Class> \n--- !ruby/class 'Class'\n", r
90
- else
91
- assert_equal "<Class> Class", r
92
- end
88
+ assert_match %r/\A<Class> (\n--- !ruby\/class ')?Class('\n)?/, r
93
89
  end
94
90
 
95
91
  def test_format_obj_without_backtrace
@@ -29,7 +29,7 @@ module TestLogging
29
29
  def test_file
30
30
  assert_equal '', @event.file
31
31
 
32
- @logger.trace = true
32
+ @logger.caller_tracing = true
33
33
  @logger.warn 'warning message'
34
34
  assert_match %r/test_log_event.rb\z/, @appender.event.file
35
35
  end
@@ -46,7 +46,7 @@ module TestLogging
46
46
  def test_line
47
47
  assert_equal '', @event.file
48
48
 
49
- @logger.trace = true
49
+ @logger.caller_tracing = true
50
50
  @logger.error 'error message'
51
51
  assert_equal __LINE__-1, @appender.event.line
52
52
  end
@@ -63,7 +63,7 @@ module TestLogging
63
63
  def test_method
64
64
  assert_equal '', @event.file
65
65
 
66
- @logger.trace = true
66
+ @logger.caller_tracing = true
67
67
  @logger.debug 'debug message'
68
68
  assert_equal 'test_method', @appender.event.method
69
69
  end
@@ -406,6 +406,33 @@ module TestLogging
406
406
  assert_equal true, logb.info?
407
407
  end
408
408
 
409
+ def test_level_with_filter
410
+ root = ::Logging::Logger[:root]
411
+ root.level = 'debug'
412
+
413
+ details_filter = ::Logging::Filters::Level.new :debug
414
+ error_filter = ::Logging::Filters::Level.new :error
415
+
416
+ a_detail = ::Logging::Appenders::StringIo.new 'detail', :filters => details_filter
417
+ a_error = ::Logging::Appenders::StringIo.new 'error', :filters => error_filter
418
+
419
+ root.add_appenders a_detail, a_error
420
+
421
+ log = ::Logging::Logger.new 'A Logger'
422
+
423
+ log.debug "debug level"
424
+ assert_equal "DEBUG A Logger : debug level\n", a_detail.readline
425
+ assert_nil a_error.readline
426
+
427
+ log.error "error level"
428
+ assert_nil a_detail.readline
429
+ assert_equal "ERROR A Logger : error level\n", a_error.readline
430
+
431
+ log.warn "warn level"
432
+ assert_nil a_detail.readline
433
+ assert_nil a_error.readline
434
+ end
435
+
409
436
  def test_log
410
437
  root = ::Logging::Logger[:root]
411
438
  root.level = 'info'
@@ -598,40 +625,40 @@ module TestLogging
598
625
  assert_raise(ArgumentError) {::Logging::Logger[:root] <=> 'string'}
599
626
  end
600
627
 
601
- def test_trace
628
+ def test_caller_tracing
602
629
  log = ::Logging::Logger[:root]
603
- assert_equal false, log.trace
630
+ assert_equal false, log.caller_tracing
604
631
 
605
- log.trace = true
606
- assert_equal true, log.trace
632
+ log.caller_tracing = true
633
+ assert_equal true, log.caller_tracing
607
634
 
608
635
  log = ::Logging::Logger['A']
609
- assert_equal false, log.trace
636
+ assert_equal false, log.caller_tracing
610
637
 
611
- log.trace = true
612
- assert_equal true, log.trace
638
+ log.caller_tracing = true
639
+ assert_equal true, log.caller_tracing
613
640
  end
614
641
 
615
- def test_trace_eq
642
+ def test_caller_trace_eq
616
643
  log = ::Logging::Logger.new 'A'
617
- assert_equal false, log.trace
644
+ assert_equal false, log.caller_tracing
618
645
 
619
- log.trace = true
620
- assert_equal true, log.trace
646
+ log.caller_tracing = true
647
+ assert_equal true, log.caller_tracing
621
648
 
622
- log.trace = false
623
- assert_equal false, log.trace
649
+ log.caller_tracing = false
650
+ assert_equal false, log.caller_tracing
624
651
 
625
- log.trace = 'true'
626
- assert_equal true, log.trace
652
+ log.caller_tracing = 'true'
653
+ assert_equal true, log.caller_tracing
627
654
 
628
- log.trace = 'false'
629
- assert_equal false, log.trace
655
+ log.caller_tracing = 'false'
656
+ assert_equal false, log.caller_tracing
630
657
 
631
- log.trace = nil
632
- assert_equal false, log.trace
658
+ log.caller_tracing = nil
659
+ assert_equal false, log.caller_tracing
633
660
 
634
- assert_raise(ArgumentError) {log.trace = Object}
661
+ assert_raise(ArgumentError) {log.caller_tracing = Object}
635
662
  end
636
663
 
637
664
  def test_dump_configuration
@@ -640,57 +667,54 @@ module TestLogging
640
667
  log_c = ::Logging::Logger['A-logger::B-logger::C-logger']
641
668
  log_d = ::Logging::Logger['A-logger::D-logger']
642
669
 
643
- sio = StringIO.new
644
- sio.extend ::Logging::Appenders::StringIo::IoToS
645
-
646
- log_a._dump_configuration( sio )
647
- assert_equal(
648
- "A-logger ........................................ debug +A -T\n", sio.to_s)
670
+ assert_equal \
671
+ "A-logger ........................................ debug +A -T\n",
672
+ log_a._dump_configuration
649
673
 
650
- log_b._dump_configuration( sio )
651
- assert_equal(
652
- "A-logger::B-logger .............................. debug +A -T\n", sio.to_s)
674
+ assert_equal \
675
+ "A-logger::B-logger .............................. debug +A -T\n",
676
+ log_b._dump_configuration
653
677
 
654
- log_c._dump_configuration( sio )
655
- assert_equal(
656
- "A-logger::B-logger::C-logger .................... debug +A -T\n", sio.to_s)
678
+ assert_equal \
679
+ "A-logger::B-logger::C-logger .................... debug +A -T\n",
680
+ log_c._dump_configuration
657
681
 
658
- log_d._dump_configuration( sio )
659
- assert_equal(
660
- "A-logger::D-logger .............................. debug +A -T\n", sio.to_s)
682
+ assert_equal \
683
+ "A-logger::D-logger .............................. debug +A -T\n",
684
+ log_d._dump_configuration
661
685
 
662
686
  log_b.level = :warn
663
- log_b.trace = true
664
- log_b._dump_configuration( sio )
665
- assert_equal(
666
- "A-logger::B-logger .............................. *warn +A +T\n", sio.to_s)
687
+ log_b.caller_tracing = true
688
+ assert_equal \
689
+ "A-logger::B-logger .............................. *warn +A +T\n",
690
+ log_b._dump_configuration
667
691
 
668
692
  log_c.additive = false
669
- log_c._dump_configuration( sio )
670
- assert_equal(
671
- "A-logger::B-logger::C-logger .................... warn -A -T\n", sio.to_s)
693
+ assert_equal \
694
+ "A-logger::B-logger::C-logger .................... warn -A -T\n",
695
+ log_c._dump_configuration
672
696
 
673
697
  # with an indent specified
674
- log_a._dump_configuration( sio, 4 )
675
- assert_equal(
676
- " A-logger .................................... debug +A -T\n", sio.to_s)
698
+ assert_equal \
699
+ " A-logger .................................... debug +A -T\n",
700
+ log_a._dump_configuration(4)
677
701
 
678
- log_b._dump_configuration( sio, 8 )
679
- assert_equal(
680
- " A-logger::B-logger ...................... *warn +A +T\n", sio.to_s)
702
+ assert_equal \
703
+ " A-logger::B-logger ...................... *warn +A +T\n",
704
+ log_b._dump_configuration(8)
681
705
 
682
- log_c._dump_configuration( sio, 10 )
683
- assert_equal(
684
- " A-logger::B-logger::C-logger .......... warn -A -T\n", sio.to_s)
706
+ assert_equal \
707
+ " A-logger::B-logger::C-logger .......... warn -A -T\n",
708
+ log_c._dump_configuration(10)
685
709
 
686
- log_d._dump_configuration( sio, 22 )
687
- assert_equal(
688
- " A-logger::D-logger ........ debug +A -T\n", sio.to_s)
710
+ assert_equal \
711
+ " A-logger::D-logger ........ debug +A -T\n",
712
+ log_d._dump_configuration(22)
689
713
 
690
714
  log_c.level = 0
691
- log_c._dump_configuration( sio, 26 )
692
- assert_equal(
693
- " A-logger::B...::C-logger *debug -A -T\n", sio.to_s)
715
+ assert_equal \
716
+ " A-logger::B...::C-logger *debug -A -T\n",
717
+ log_c._dump_configuration(26)
694
718
  end
695
719
 
696
720
  end # class TestLogger