File: logging_helper.rb

package info (click to toggle)
ruby-logging 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 660 kB
  • sloc: ruby: 6,139; sh: 11; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 960 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

module RSpec
  module LoggingHelper

    # Capture log messages from the Logging framework and make them
    # available via a @log_output instance variable. The @log_output
    # supports a readline method to access the log messages.
    #
    def capture_log_messages( opts = {} )
      from = opts.fetch(:from, 'root')
      to = opts.fetch(:to, '__rspec__')
      exclusive = opts.fetch(:exclusive, true)

      appender = Logging::Appenders[to] || Logging::Appenders::StringIo.new(to)
      logger = Logging::Logger[from]
      if exclusive
        logger.appenders = appender
      else
        logger.add_appenders(appender)
      end

      before(:all) do
        @log_output = Logging::Appenders[to]
      end

      before(:each) do
        @log_output.reset
      end
    end

  end  # module LoggingHelper
end  # module RSpec

if defined?  RSpec::Core::Configuration
  class RSpec::Core::Configuration
    include RSpec::LoggingHelper
  end
end