Sha256: c5531f97a342198e39a1c773c93ac22ce541f7928f8a83e3de641cfbe008c5f5

Contents?: true

Size: 800 Bytes

Versions: 3

Compression:

Stored size: 800 Bytes

Contents

require_relative 'spec_helper'
require 'strftime_logger'
require 'fileutils'

describe StrftimeLogger do
  subject do
    StrftimeLogger.new("#{log_dir}/application.log.%Y%m%d").tap {|logger|
      logger.formatter = StrftimeLogger::LtsvFormatter.new
    }
  end
  let(:log_dir)   { "#{File.dirname(__FILE__)}/log" }
  let(:today)     { Time.now.strftime "%Y%m%d"}
  let(:now)       { Time.now.iso8601 }

  before do
    Dir.mkdir(log_dir)
    Timecop.freeze(Time.now)
  end

  after do
    FileUtils.rm_rf log_dir
    Timecop.return
  end

  it :write do
    subject.write("test")
    subject.write({a:1, b:2})
    File.open("#{log_dir}/application.log.#{today}") do |f|
      expect(f.gets).to eq "time:#{now}\tmessage:test\n"
      expect(f.gets).to eq "time:#{now}\ta:1\tb:2\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strftime_logger-0.0.4 spec/ltsv_formatter_spec.rb
strftime_logger-0.0.3 spec/ltsv_formatter_spec.rb
strftime_logger-0.0.2 spec/ltsv_formatter_spec.rb