File: app_logger.rb

package info (click to toggle)
camping 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: ruby: 5,032; javascript: 2,362; makefile: 29
file content (70 lines) | stat: -rw-r--r-- 1,880 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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