logging 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,24 +84,32 @@ module Logging::Appenders
84
84
  # 'date'.
85
85
  #
86
86
  def initialize( name, opts = {} )
87
- @roller = Roller.new name, opts
87
+ @roller = Roller.new(
88
+ opts.fetch(:filename, name),
89
+ age: opts.fetch(:age, nil),
90
+ size: opts.fetch(:size, nil),
91
+ roll_by: opts.fetch(:roll_by, nil),
92
+ keep: opts.fetch(:keep, nil)
93
+ )
88
94
 
89
95
  # grab our options
90
96
  @size = opts.fetch(:size, nil)
91
97
  @size = Integer(@size) unless @size.nil?
92
98
 
93
- @age_fn = filename + '.age'
99
+ @age_fn = self.filename + '.age'
94
100
  @age_fn_mtime = nil
95
101
  @age = opts.fetch(:age, nil)
96
102
 
97
103
  # create our `sufficiently_aged?` method
98
104
  build_singleton_methods
99
- FileUtils.touch(@age_fn) if @age && !test(?f, @age_fn)
105
+ FileUtils.touch(@age_fn) if @age && !::File.file?(@age_fn)
100
106
 
101
107
  # we are opening the file in read/write mode so that a shared lock can
102
108
  # be used on the file descriptor => http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.html
103
- @mode = encoding ? "a+:#{encoding}" : 'a+'
104
- super(name, ::File.new(filename, @mode), opts)
109
+ self.encoding = opts.fetch(:encoding, self.encoding)
110
+
111
+ io = open_file
112
+ super(name, io, opts)
105
113
 
106
114
  # if the truncate flag was set to true, then roll
107
115
  roll_now = opts.fetch(:truncate, false)
@@ -121,11 +129,11 @@ module Logging::Appenders
121
129
  # is currently open then it will be closed and immediately opened.
122
130
  def reopen
123
131
  @mutex.synchronize {
124
- if defined?(@io) && @io
132
+ if defined? @io && @io
125
133
  flush
126
134
  @io.close rescue nil
127
135
  end
128
- @io = ::File.new(filename, @mode)
136
+ @io = open_file
129
137
  }
130
138
  super
131
139
  self
@@ -134,6 +142,20 @@ module Logging::Appenders
134
142
 
135
143
  private
136
144
 
145
+ def open_file
146
+ mode = ::File::RDWR | ::File::APPEND
147
+ ::File.open(filename, mode: mode, external_encoding: encoding)
148
+ rescue Errno::ENOENT
149
+ create_file
150
+ end
151
+
152
+ def create_file
153
+ mode = ::File::RDWR | ::File::APPEND | ::File::CREAT | ::File::EXCL
154
+ ::File.open(filename, mode: mode, external_encoding: encoding)
155
+ rescue Errno::EEXIST
156
+ open_file
157
+ end
158
+
137
159
  # Returns the file name to use as the temporary copy location. We are
138
160
  # using copy-and-truncate semantics for rolling files so that the IO
139
161
  # file descriptor remains valid during rolling.
@@ -157,14 +179,18 @@ module Logging::Appenders
157
179
  return self if @io.nil?
158
180
 
159
181
  str = str.force_encoding(encoding) if encoding && str.encoding != encoding
160
- @io.flock_sh { @io.write str }
182
+ @mutex.synchronize {
183
+ @io.flock_sh { @io.write str }
184
+ }
161
185
 
162
186
  if roll_required?
163
- @io.flock? {
164
- @age_fn_mtime = nil
165
- copy_truncate if roll_required?
187
+ @mutex.synchronize {
188
+ @io.flock? {
189
+ @age_fn_mtime = nil
190
+ copy_truncate if roll_required?
191
+ }
192
+ @roller.roll_files
166
193
  }
167
- @roller.roll_files
168
194
  end
169
195
  self
170
196
  rescue StandardError => err
@@ -193,7 +219,7 @@ module Logging::Appenders
193
219
  def copy_truncate
194
220
  return unless ::File.exist?(filename)
195
221
  FileUtils.concat filename, copy_file
196
- @io.truncate 0
222
+ @io.truncate(0)
197
223
 
198
224
  # touch the age file if needed
199
225
  if @age
@@ -255,22 +281,22 @@ module Logging::Appenders
255
281
  # Create a new roller. See the RollingFile#initialize documentation for
256
282
  # the list of options.
257
283
  #
258
- # name - The appender name as a String
259
- # opts - The options Hash
284
+ # filename - the name of the file to roll
285
+ # age - the age of the file at which it should be rolled
286
+ # size - the size of the file in bytes at which it should be rolled
287
+ # roll_by - roll either by 'number' or 'date'
288
+ # keep - the number of log files to keep when rolling
260
289
  #
261
- def initialize( name, opts )
290
+ def initialize( filename, age: nil, size: nil, roll_by: nil, keep: nil )
262
291
  # raise an error if a filename was not given
263
- @fn = opts.fetch(:filename, name)
292
+ @fn = filename
264
293
  raise ArgumentError, 'no filename was given' if @fn.nil?
265
294
 
266
295
  if (m = RGXP.match @fn)
267
296
  @roll_by = ("#{m[2]}%d" == m[1]) ? :number : :date
268
297
  else
269
- age = opts.fetch(:age, nil)
270
- size = opts.fetch(:size, nil)
271
-
272
298
  @roll_by =
273
- case opts.fetch(:roll_by, nil)
299
+ case roll_by
274
300
  when 'number'; :number
275
301
  when 'date'; :date
276
302
  else
@@ -293,8 +319,7 @@ module Logging::Appenders
293
319
  ::Logging::Appenders::File.assert_valid_logfile(filename)
294
320
 
295
321
  @roll = false
296
- @keep = opts.fetch(:keep, nil)
297
- @keep = Integer(keep) unless keep.nil?
322
+ @keep = keep.nil? ? nil : Integer(keep)
298
323
  end
299
324
 
300
325
  attr_reader :keep, :roll_by
@@ -347,7 +372,6 @@ module Logging::Appenders
347
372
  files.delete copy_file
348
373
 
349
374
  self.send "roll_by_#{roll_by}", files
350
-
351
375
  nil
352
376
  ensure
353
377
  self.roll = false
@@ -62,7 +62,7 @@ module Logging::Appenders
62
62
  %w[read readline readlines].each do|m|
63
63
  class_eval <<-CODE, __FILE__, __LINE__+1
64
64
  def #{m}( *args )
65
- sync {
65
+ @mutex.synchronize {
66
66
  begin
67
67
  @sio.seek @pos
68
68
  rv = @sio.#{m}(*args)
@@ -188,7 +188,7 @@ module Logging::Appenders
188
188
  end
189
189
  return if message.empty?
190
190
 
191
- @syslog.log(pri, '%s', message)
191
+ @mutex.synchronize { @syslog.log(pri, '%s', message) }
192
192
  self
193
193
  end
194
194
 
@@ -205,11 +205,10 @@ module Logging::Appenders
205
205
  level = level.to_s.upcase
206
206
  self.class.const_get level
207
207
  else
208
- raise ArgumentError, "unkonwn level '#{level}'"
208
+ raise ArgumentError, "unknown level '#{level}'"
209
209
  end
210
210
  end
211
211
 
212
212
  end # Syslog
213
213
  end # Logging::Appenders
214
214
  end # HAVE_SYSLOG
215
-
@@ -103,7 +103,7 @@ module Logging::Layouts
103
103
  'message' => 'format_obj(event.data)'.freeze,
104
104
  'file' => 'event.file'.freeze,
105
105
  'line' => 'event.line'.freeze,
106
- 'method' => 'event.method'.freeze,
106
+ 'method' => 'event.method_name'.freeze,
107
107
  'hostname' => "'#{Socket.gethostname}'".freeze,
108
108
  'pid' => 'Process.pid'.freeze,
109
109
  'millis' => 'Integer((event.time-@created_at)*1000)'.freeze,
@@ -307,7 +307,7 @@ module Logging::Layouts
307
307
  'l' => '::Logging::LNAMES[event.level]'.freeze,
308
308
  'L' => 'event.line'.freeze,
309
309
  'm' => 'format_obj(event.data)'.freeze,
310
- 'M' => 'event.method'.freeze,
310
+ 'M' => 'event.method_name'.freeze,
311
311
  'h' => "'#{Socket.gethostname}'".freeze,
312
312
  'p' => 'Process.pid'.freeze,
313
313
  'r' => 'Integer((event.time-@created_at)*1000).to_s'.freeze,
@@ -15,7 +15,7 @@ module Logging
15
15
  CALLER_INDEX = ((defined? JRUBY_VERSION and JRUBY_VERSION > '1.6') or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2
16
16
  # :startdoc:
17
17
 
18
- attr_accessor :logger, :level, :data, :time, :file, :line, :method
18
+ attr_accessor :logger, :level, :data, :time, :file, :line, :method_name
19
19
 
20
20
  # call-seq:
21
21
  # LogEvent.new( logger, level, [data], caller_tracing )
@@ -36,15 +36,15 @@ module Logging
36
36
  return if stack.nil?
37
37
 
38
38
  match = CALLER_RGXP.match(stack)
39
- self.file = match[1]
40
- self.line = Integer(match[2])
41
- self.method = match[3] unless match[3].nil?
39
+ self.file = match[1]
40
+ self.line = Integer(match[2])
41
+ self.method_name = match[3] unless match[3].nil?
42
42
 
43
43
  if (bp = ::Logging.basepath) && !bp.empty? && file.index(bp) == 0
44
44
  self.file = file.slice(bp.length + 1, file.length - bp.length)
45
45
  end
46
46
  else
47
- self.file = self.line = self.method = ''
47
+ self.file = self.line = self.method_name = ''
48
48
  end
49
49
  end
50
50
  end
@@ -24,8 +24,6 @@ module Logging
24
24
  #
25
25
  class Logger
26
26
 
27
- @mutex = Mutex.new # :nodoc:
28
-
29
27
  # Returns the root logger.
30
28
  def self.root
31
29
  ::Logging::Repository.instance[:root]
@@ -48,7 +46,10 @@ module Logging
48
46
  logger = repo[name]
49
47
  return logger unless logger.nil?
50
48
 
51
- @mutex.synchronize do
49
+ # Share the same mutex that's used by 'define_log_methods' because
50
+ # it iterates over the hash of loggers, and adding a new key to a hash
51
+ # while iterating over it produces an error.
52
+ ::Logging::Logger.mutex.synchronize do
52
53
  logger = repo[name]
53
54
  return logger unless logger.nil? # thread-safe double checking
54
55
 
@@ -118,6 +119,14 @@ module Logging
118
119
  code.join("\n")
119
120
  end
120
121
 
122
+ @mutex = ReentrantMutex.new
123
+
124
+ # Returns a global ReentrantMutex for use when creating Logger instances
125
+ # and/or updating log levels.
126
+ def self.mutex
127
+ @mutex
128
+ end
129
+
121
130
  attr_reader :name, :parent, :additive, :caller_tracing
122
131
 
123
132
  # call-seq:
@@ -411,7 +420,7 @@ module Logging
411
420
  def define_log_methods( force = false, code = nil )
412
421
  return if has_own_level? and !force
413
422
 
414
- ::Logging::Logger._reentrant_mutex.synchronize do
423
+ ::Logging::Logger.mutex.synchronize do
415
424
  ::Logging::Logger.define_log_methods(self)
416
425
  ::Logging::Repository.instance.children(name).each do |child|
417
426
  child.define_log_methods
@@ -423,12 +432,6 @@ module Logging
423
432
  # :stopdoc:
424
433
  public
425
434
 
426
- @reentrant_mutex = ReentrantMutex.new
427
-
428
- def self._reentrant_mutex
429
- @reentrant_mutex
430
- end
431
-
432
435
  # call-seq:
433
436
  # _meta_eval( code )
434
437
  #
@@ -511,6 +514,5 @@ module Logging
511
514
  end
512
515
  # :startdoc:
513
516
 
514
- end # Logger
515
- end # Logging
516
-
517
+ end
518
+ end
@@ -47,7 +47,7 @@ module Logging
47
47
 
48
48
  # All hail the magic of method missing. Here is where we are going to log
49
49
  # the method call and then forward to the proxied object. The return value
50
- # from the proxied objet method call is passed back.
50
+ # from the proxied object method call is passed back.
51
51
  #
52
52
  def method_missing( name, *args, &block )
53
53
  @logger << "#@leader#{name}(#{args.inspect[1..-2]})\n"
@@ -1,5 +1,5 @@
1
1
  module Logging
2
- VERSION = "2.2.2".freeze
2
+ VERSION = "2.3.0".freeze
3
3
 
4
4
  # Returns the version string for the library.
5
5
  def self.version
@@ -1,45 +1,44 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: logging 2.1.0.48 ruby lib
2
+ # stub: logging 2.3.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "logging".freeze
6
- s.version = "2.1.0.48"
6
+ s.version = "2.3.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Tim Pease".freeze]
11
- s.date = "2017-01-08"
11
+ s.date = "2020-07-04"
12
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.".freeze
13
13
  s.email = "tim.pease@gmail.com".freeze
14
14
  s.extra_rdoc_files = ["History.txt".freeze]
15
- s.files = [".gitignore".freeze, ".travis.yml".freeze, "History.txt".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "examples/appenders.rb".freeze, "examples/classes.rb".freeze, "examples/colorization.rb".freeze, "examples/custom_log_levels.rb".freeze, "examples/fork.rb".freeze, "examples/formatting.rb".freeze, "examples/hierarchies.rb".freeze, "examples/layouts.rb".freeze, "examples/lazy.rb".freeze, "examples/loggers.rb".freeze, "examples/mdc.rb".freeze, "examples/names.rb".freeze, "examples/rails4.rb".freeze, "examples/reusing_layouts.rb".freeze, "examples/rspec_integration.rb".freeze, "examples/simple.rb".freeze, "lib/logging.rb".freeze, "lib/logging/appender.rb".freeze, "lib/logging/appenders.rb".freeze, "lib/logging/appenders/buffering.rb".freeze, "lib/logging/appenders/console.rb".freeze, "lib/logging/appenders/file.rb".freeze, "lib/logging/appenders/io.rb".freeze, "lib/logging/appenders/rolling_file.rb".freeze, "lib/logging/appenders/string_io.rb".freeze, "lib/logging/appenders/syslog.rb".freeze, "lib/logging/color_scheme.rb".freeze, "lib/logging/diagnostic_context.rb".freeze, "lib/logging/filter.rb".freeze, "lib/logging/filters.rb".freeze, "lib/logging/filters/level.rb".freeze, "lib/logging/layout.rb".freeze, "lib/logging/layouts.rb".freeze, "lib/logging/layouts/basic.rb".freeze, "lib/logging/layouts/parseable.rb".freeze, "lib/logging/layouts/pattern.rb".freeze, "lib/logging/log_event.rb".freeze, "lib/logging/logger.rb".freeze, "lib/logging/proxy.rb".freeze, "lib/logging/rails_compat.rb".freeze, "lib/logging/repository.rb".freeze, "lib/logging/root_logger.rb".freeze, "lib/logging/utils.rb".freeze, "lib/logging/version.rb".freeze, "lib/rspec/logging_helper.rb".freeze, "lib/spec/logging_helper.rb".freeze, "logging.gemspec".freeze, "script/bootstrap".freeze, "script/console".freeze, "test/appenders/test_async_flushing.rb".freeze, "test/appenders/test_buffered_io.rb".freeze, "test/appenders/test_console.rb".freeze, "test/appenders/test_file.rb".freeze, "test/appenders/test_io.rb".freeze, "test/appenders/test_rolling_file.rb".freeze, "test/appenders/test_string_io.rb".freeze, "test/appenders/test_syslog.rb".freeze, "test/benchmark.rb".freeze, "test/layouts/test_basic.rb".freeze, "test/layouts/test_color_pattern.rb".freeze, "test/layouts/test_json.rb".freeze, "test/layouts/test_pattern.rb".freeze, "test/layouts/test_yaml.rb".freeze, "test/performance.rb".freeze, "test/setup.rb".freeze, "test/test_appender.rb".freeze, "test/test_color_scheme.rb".freeze, "test/test_filter.rb".freeze, "test/test_layout.rb".freeze, "test/test_log_event.rb".freeze, "test/test_logger.rb".freeze, "test/test_logging.rb".freeze, "test/test_mapped_diagnostic_context.rb".freeze, "test/test_nested_diagnostic_context.rb".freeze, "test/test_proxy.rb".freeze, "test/test_repository.rb".freeze, "test/test_root_logger.rb".freeze, "test/test_utils.rb".freeze]
15
+ s.files = [".gitignore".freeze, ".travis.yml".freeze, "History.txt".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "examples/appenders.rb".freeze, "examples/classes.rb".freeze, "examples/colorization.rb".freeze, "examples/custom_log_levels.rb".freeze, "examples/fork.rb".freeze, "examples/formatting.rb".freeze, "examples/hierarchies.rb".freeze, "examples/layouts.rb".freeze, "examples/lazy.rb".freeze, "examples/loggers.rb".freeze, "examples/mdc.rb".freeze, "examples/names.rb".freeze, "examples/rails4.rb".freeze, "examples/reusing_layouts.rb".freeze, "examples/rspec_integration.rb".freeze, "examples/simple.rb".freeze, "lib/logging.rb".freeze, "lib/logging/appender.rb".freeze, "lib/logging/appenders.rb".freeze, "lib/logging/appenders/buffering.rb".freeze, "lib/logging/appenders/console.rb".freeze, "lib/logging/appenders/file.rb".freeze, "lib/logging/appenders/io.rb".freeze, "lib/logging/appenders/rolling_file.rb".freeze, "lib/logging/appenders/string_io.rb".freeze, "lib/logging/appenders/syslog.rb".freeze, "lib/logging/color_scheme.rb".freeze, "lib/logging/diagnostic_context.rb".freeze, "lib/logging/filter.rb".freeze, "lib/logging/filters.rb".freeze, "lib/logging/filters/level.rb".freeze, "lib/logging/layout.rb".freeze, "lib/logging/layouts.rb".freeze, "lib/logging/layouts/basic.rb".freeze, "lib/logging/layouts/parseable.rb".freeze, "lib/logging/layouts/pattern.rb".freeze, "lib/logging/log_event.rb".freeze, "lib/logging/logger.rb".freeze, "lib/logging/proxy.rb".freeze, "lib/logging/rails_compat.rb".freeze, "lib/logging/repository.rb".freeze, "lib/logging/root_logger.rb".freeze, "lib/logging/utils.rb".freeze, "lib/logging/version.rb".freeze, "lib/rspec/logging_helper.rb".freeze, "lib/spec/logging_helper.rb".freeze, "logging.gemspec".freeze, "script/bootstrap".freeze, "script/console".freeze, "test/appenders/test_async_flushing.rb".freeze, "test/appenders/test_buffered_io.rb".freeze, "test/appenders/test_console.rb".freeze, "test/appenders/test_file.rb".freeze, "test/appenders/test_io.rb".freeze, "test/appenders/test_rolling_file.rb".freeze, "test/appenders/test_string_io.rb".freeze, "test/appenders/test_syslog.rb".freeze, "test/benchmark.rb".freeze, "test/layouts/test_basic.rb".freeze, "test/layouts/test_color_pattern.rb".freeze, "test/layouts/test_json.rb".freeze, "test/layouts/test_nested_exceptions.rb".freeze, "test/layouts/test_pattern.rb".freeze, "test/layouts/test_yaml.rb".freeze, "test/performance.rb".freeze, "test/setup.rb".freeze, "test/test_appender.rb".freeze, "test/test_color_scheme.rb".freeze, "test/test_filter.rb".freeze, "test/test_layout.rb".freeze, "test/test_log_event.rb".freeze, "test/test_logger.rb".freeze, "test/test_logging.rb".freeze, "test/test_mapped_diagnostic_context.rb".freeze, "test/test_nested_diagnostic_context.rb".freeze, "test/test_proxy.rb".freeze, "test/test_repository.rb".freeze, "test/test_root_logger.rb".freeze, "test/test_utils.rb".freeze]
16
16
  s.homepage = "http://rubygems.org/gems/logging".freeze
17
17
  s.rdoc_options = ["--main".freeze, "README.md".freeze]
18
- s.rubyforge_project = "logging".freeze
19
- s.rubygems_version = "2.5.2".freeze
18
+ s.rubygems_version = "3.0.1".freeze
20
19
  s.summary = "A flexible and extendable logging library for Ruby".freeze
21
- s.test_files = ["test/appenders/test_async_flushing.rb".freeze, "test/appenders/test_buffered_io.rb".freeze, "test/appenders/test_console.rb".freeze, "test/appenders/test_file.rb".freeze, "test/appenders/test_io.rb".freeze, "test/appenders/test_rolling_file.rb".freeze, "test/appenders/test_string_io.rb".freeze, "test/appenders/test_syslog.rb".freeze, "test/layouts/test_basic.rb".freeze, "test/layouts/test_color_pattern.rb".freeze, "test/layouts/test_json.rb".freeze, "test/layouts/test_pattern.rb".freeze, "test/layouts/test_yaml.rb".freeze, "test/test_appender.rb".freeze, "test/test_color_scheme.rb".freeze, "test/test_filter.rb".freeze, "test/test_layout.rb".freeze, "test/test_log_event.rb".freeze, "test/test_logger.rb".freeze, "test/test_logging.rb".freeze, "test/test_mapped_diagnostic_context.rb".freeze, "test/test_nested_diagnostic_context.rb".freeze, "test/test_proxy.rb".freeze, "test/test_repository.rb".freeze, "test/test_root_logger.rb".freeze, "test/test_utils.rb".freeze]
20
+ s.test_files = ["test/appenders/test_async_flushing.rb".freeze, "test/appenders/test_buffered_io.rb".freeze, "test/appenders/test_console.rb".freeze, "test/appenders/test_file.rb".freeze, "test/appenders/test_io.rb".freeze, "test/appenders/test_rolling_file.rb".freeze, "test/appenders/test_string_io.rb".freeze, "test/appenders/test_syslog.rb".freeze, "test/layouts/test_basic.rb".freeze, "test/layouts/test_color_pattern.rb".freeze, "test/layouts/test_json.rb".freeze, "test/layouts/test_nested_exceptions.rb".freeze, "test/layouts/test_pattern.rb".freeze, "test/layouts/test_yaml.rb".freeze, "test/test_appender.rb".freeze, "test/test_color_scheme.rb".freeze, "test/test_filter.rb".freeze, "test/test_layout.rb".freeze, "test/test_log_event.rb".freeze, "test/test_logger.rb".freeze, "test/test_logging.rb".freeze, "test/test_mapped_diagnostic_context.rb".freeze, "test/test_nested_diagnostic_context.rb".freeze, "test/test_proxy.rb".freeze, "test/test_repository.rb".freeze, "test/test_root_logger.rb".freeze, "test/test_utils.rb".freeze]
22
21
 
23
22
  if s.respond_to? :specification_version then
24
23
  s.specification_version = 4
25
24
 
26
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
26
  s.add_runtime_dependency(%q<little-plugger>.freeze, ["~> 1.1"])
28
- s.add_runtime_dependency(%q<multi_json>.freeze, ["~> 1.10"])
29
- s.add_development_dependency(%q<test-unit>.freeze, ["~> 3.1"])
27
+ s.add_runtime_dependency(%q<multi_json>.freeze, ["~> 1.14"])
28
+ s.add_development_dependency(%q<test-unit>.freeze, ["~> 3.3"])
30
29
  s.add_development_dependency(%q<bones-git>.freeze, ["~> 1.3"])
31
30
  s.add_development_dependency(%q<bones>.freeze, [">= 3.8.4"])
32
31
  else
33
32
  s.add_dependency(%q<little-plugger>.freeze, ["~> 1.1"])
34
- s.add_dependency(%q<multi_json>.freeze, ["~> 1.10"])
35
- s.add_dependency(%q<test-unit>.freeze, ["~> 3.1"])
33
+ s.add_dependency(%q<multi_json>.freeze, ["~> 1.14"])
34
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3.3"])
36
35
  s.add_dependency(%q<bones-git>.freeze, ["~> 1.3"])
37
36
  s.add_dependency(%q<bones>.freeze, [">= 3.8.4"])
38
37
  end
39
38
  else
40
39
  s.add_dependency(%q<little-plugger>.freeze, ["~> 1.1"])
41
- s.add_dependency(%q<multi_json>.freeze, ["~> 1.10"])
42
- s.add_dependency(%q<test-unit>.freeze, ["~> 3.1"])
40
+ s.add_dependency(%q<multi_json>.freeze, ["~> 1.14"])
41
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3.3"])
43
42
  s.add_dependency(%q<bones-git>.freeze, ["~> 1.3"])
44
43
  s.add_dependency(%q<bones>.freeze, [">= 3.8.4"])
45
44
  end
@@ -194,24 +194,22 @@ module TestAppenders
194
194
  assert_nil(readline)
195
195
  end
196
196
 
197
- if Object.const_defined?(:Encoding)
198
- def test_force_encoding
199
- a = 'ümlaut'
200
- b = 'hello ümlaut'.force_encoding('BINARY')
201
-
202
- event_a = Logging::LogEvent.new('TestLogger', @levels['info'], a, false)
203
- event_b = Logging::LogEvent.new('TestLogger', @levels['info'], b, false)
204
-
205
- @appender.append event_a
206
- @appender.append event_b
207
- assert_nil(readline)
208
-
209
- @appender.append event_a
210
- assert_equal " INFO TestLogger : #{a}\n", readline
211
- assert_equal " INFO TestLogger : #{b.force_encoding('UTF-8')}\n", readline
212
- assert_equal " INFO TestLogger : #{a}\n", readline
213
- assert_nil(readline)
214
- end
197
+ def test_force_encoding
198
+ a = 'ümlaut'
199
+ b = 'hello ümlaut'.force_encoding('BINARY')
200
+
201
+ event_a = Logging::LogEvent.new('TestLogger', @levels['info'], a, false)
202
+ event_b = Logging::LogEvent.new('TestLogger', @levels['info'], b, false)
203
+
204
+ @appender.append event_a
205
+ @appender.append event_b
206
+ assert_nil(readline)
207
+
208
+ @appender.append event_a
209
+ assert_equal " INFO TestLogger : #{a}\n", readline
210
+ assert_equal " INFO TestLogger : #{b.force_encoding('UTF-8')}\n", readline
211
+ assert_equal " INFO TestLogger : #{a}\n", readline
212
+ assert_nil(readline)
215
213
  end
216
214
 
217
215
  private
@@ -20,11 +20,10 @@ module TestAppenders
20
20
 
21
21
  appender = Logging.appenders.stdout
22
22
  assert_equal 'stdout', appender.name
23
- assert_same STDOUT, appender.instance_variable_get(:@io)
24
23
 
25
- appender.close
26
- assert_equal true, appender.closed?
27
- assert_equal false, STDOUT.closed?
24
+ io = appender.instance_variable_get(:@io)
25
+ refute_same STDOUT, io
26
+ assert_equal STDOUT.fileno, io.fileno
28
27
 
29
28
  appender = Logging.appenders.stdout('foo')
30
29
  assert_equal 'foo', appender.name
@@ -38,7 +37,26 @@ module TestAppenders
38
37
  assert_equal 3, appender.level
39
38
  end
40
39
 
41
- end # class TestStdout
40
+ def test_reopen
41
+ Logging::Repository.instance
42
+
43
+ appender = Logging.appenders.stdout
44
+ io = appender.instance_variable_get(:@io)
45
+
46
+ appender.close
47
+ assert appender.closed?
48
+ assert io.closed?
49
+ refute STDOUT.closed?
50
+
51
+ appender.reopen
52
+ refute appender.closed?
53
+
54
+ new_io = appender.instance_variable_get(:@io)
55
+ refute_same io, new_io
56
+ refute new_io.closed?
57
+ assert io.closed?
58
+ end
59
+ end
42
60
 
43
61
  class TestStderr < Test::Unit::TestCase
44
62
  include LoggingTestCase
@@ -48,11 +66,10 @@ module TestAppenders
48
66
 
49
67
  appender = Logging.appenders.stderr
50
68
  assert_equal 'stderr', appender.name
51
- assert_same STDERR, appender.instance_variable_get(:@io)
52
69
 
53
- appender.close
54
- assert_equal true, appender.closed?
55
- assert_equal false, STDERR.closed?
70
+ io = appender.instance_variable_get(:@io)
71
+ refute_same STDERR, io
72
+ assert_same STDERR.fileno, io.fileno
56
73
 
57
74
  appender = Logging.appenders.stderr('foo')
58
75
  assert_equal 'foo', appender.name
@@ -66,8 +83,26 @@ module TestAppenders
66
83
  assert_equal 3, appender.level
67
84
  end
68
85
 
69
- end # class TestStderr
86
+ def test_reopen
87
+ Logging::Repository.instance
70
88
 
71
- end # module TestAppenders
72
- end # module TestLogging
89
+ appender = Logging.appenders.stderr
90
+ io = appender.instance_variable_get(:@io)
91
+
92
+ appender.close
93
+ assert appender.closed?
94
+ assert io.closed?
95
+ refute STDERR.closed?
96
+
97
+ appender.reopen
98
+ refute appender.closed?
99
+
100
+ new_io = appender.instance_variable_get(:@io)
101
+ refute_same io, new_io
102
+ refute new_io.closed?
103
+ assert io.closed?
104
+ end
105
+ end
106
+ end
107
+ end
73
108