Sha256: 1ca47792ae09e4e8ae41a8d4bbff82fb4985ba2ebadd9a7f41448935c7eeed05

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

module SemanticLogger
  module Test
    # Logging class to captures all logging events in memory.
    #
    # Example:
    #
    # class UserTest < ActiveSupport::TestCase
    #   describe User do
    #     let(:capture_logger) { SemanticLogger::Test::CaptureLogEvents.new }
    #     let(:user) { User.new }
    #
    #     it "logs message" do
    #       user.stub(:logger, capture_logger) do
    #         user.enable!
    #       end
    #       assert_equal "Hello World", capture_logger.events.last.message
    #       assert_equal :info, capture_logger.events.last.level
    #     end
    #   end
    # end
    class CaptureLogEvents < SemanticLogger::Subscriber
      attr_accessor :events

      # By default collect all log levels, and collect metric only log events.
      def initialize(level: :trace, metrics: true)
        super(level: level, metrics: true)
      end

      def log(log)
        (@events ||= []) << log
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
semantic_logger-4.12.0 lib/semantic_logger/test/capture_log_events.rb
semantic_logger-4.11.0 lib/semantic_logger/test/capture_log_events.rb
semantic_logger-4.10.0 lib/semantic_logger/test/capture_log_events.rb
semantic_logger-4.9.0 lib/semantic_logger/test/capture_log_events.rb