Sha256: b9053135c024c22abd585621d4fbb016ae6cbde9966f2d7974518f083b448b15

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'
module ActiveSupport
  class Logger
    class Formatter
      def call(severity, timestamp, program, message)
        message
      end
    end
  end
  module TaggedLogging
    module Formatter
    end
  end
end
require 'betterlog/log/legacy_event_formatter'

describe Betterlog::Log::LegacyEventFormatter do
  let :red do
    Term::ANSIColor.red { "red" }
  end

  it 'strips blank messages' do
    message = described_class.new.(:info, Time.now, 'foo', '    ')
    expect(message).to eq ?\n
  end

  it 'uncolors colored message strings' do
    json = described_class.new.(:info, Time.now, 'foo', red)
    data = JSON.parse(json)
    expect(data['message']).to eq 'red'
  end

  it 'deconstructs backtraces' do
    msg = <<~end
    foo.rb:6:in `bar': hi (RuntimeError)
        from foo.rb:2:in `foo'
        from foo.rb:9:in `<main>'
    end
    json = described_class.new.(:info, Time.now, 'foo', msg)
    data = JSON.parse(json)
    expect(data['message']).to eq "foo.rb:6:in `bar': hi (RuntimeError)\n"
    expect(data['backtrace']).to eq [
      "foo.rb:6:in `bar': hi (RuntimeError)",
      "    from foo.rb:2:in `foo'",
      "    from foo.rb:9:in `<main>'"
    ]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
betterlog-2.0.4 spec/betterlog/log/legacy_event_formatter_spec.rb