Skip to content

Commit 2979c09

Browse files
jpervillegkellogg
authored andcommitted
Use the same DelegateClass(IO) each time we instanciate a logger
1 parent 43d34a7 commit 2979c09

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/rdf/util/logger.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module RDF; module Util
99
# Modules must provide `@logger`, which returns an instance of `Logger`, or something responding to `#<<`. Logger may also be specified using an `@options` hash containing a `:logger` entry.
1010
# @since 2.0.0
1111
module Logger
12+
# The IOWrapper class is used to store per-logger state while wrapping an IO such as $stderr.
13+
IOWrapper = DelegateClass(IO)
14+
1215
##
1316
# Logger instance, found using `options[:logger]`, `@logger`, or `@options[:logger]`
1417
# @param [Hash{Symbol => Object}] options
@@ -19,7 +22,7 @@ def logger(**options)
1922
logger = @options[:logger] if logger.nil? && @options
2023
if logger.nil?
2124
# Unless otherwise specified, use $stderr
22-
logger = (@options || options)[:logger] = DelegateClass(IO).new($stderr)
25+
logger = (@options || options)[:logger] = IOWrapper.new($stderr)
2326

2427
# Reset log_statistics so that it's not inherited across different instances
2528
logger.log_statistics.clear if logger.respond_to?(:log_statistics)

0 commit comments

Comments
 (0)