Sha256: 097733306c7389823753da69c358b3eed4821560f52582ca9cb1a1b52253b7fb

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'
require 'camping'

Camping.goes :Loggy

Loggy.pack Gear::Firewatch

module Loggy::Controllers

  class Index
    def get
      # @env['rack.errors'] = StringIO.new
      log.debug("Created Logger")
      log.info("Program Started")
      log.warn("Nothing to do!")
      log "what up"
    end
  end
end

class Loggy::Test < TestCase

  def logs
    File.read Dir["./**/logs/development.log"].first
  end

  def after_all
    `rm -rf logs` if File.exist?('logs/development.log')
    `rm -rf logs` if File.exist?('logs/formatter.log')
    `rm -rf logs` if File.exist?('logs/production.log')
    super
  end

  def test_logging
    get '/'
    assert_log "Program Started"
    assert_log "INFO"
  end

  def test_log_levels
    get '/'
    assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
    assert(/(WARN).*Nothing to do!$/.match?(logs), "Log level of WARN not found.")
  end

  def test_log_on_error
    get '/'
    assert_raises {
      raise "[Error]: There was a big error and I don't like it."
    }
  end

  def test_change_log_location
    Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch::default_template).add_backend(stream: "logs/production.log")
    puts Camping::Firewatch.logger
    get '/'
    lags = File.read Dir["./**/logs/production.log"].first
    assert(/(INFO).*Program Started$/.match?(lags), "Log level of INFO not found.")

    # the end of the test means we set it back.
    Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch::default_template).add_backend(stream: "logs/development.log")
  end

  # def test_changing_loggging_formatter
  #   logger = Dry.Logger(:Camping, formatter: :rack).add_backend(stream: "logs/formatter.log")
  #   get '/'
  #   assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
  # end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
camping-3.2.6 test/app_logger.rb
camping-3.2.5 test/app_logger.rb
camping-3.2.4 test/app_logger.rb
camping-3.2.3 test/app_logger.rb
camping-3.2.2 test/app_logger.rb
camping-3.2.1 test/app_logger.rb