simple-rack-logger 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,12 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in simple_rack_logger.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'rspec'
8
- gem 'guard-rspec'
9
- gem 'rb-inotify'
10
- gem 'guard-bundler'
11
- gem 'rack-test'
12
- end
4
+ gemspec
data/Guardfile CHANGED
@@ -1,5 +1,11 @@
1
1
  guard 'rspec', cli: "--color --format nested" do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/(.*)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ # Uncomment next line if Gemfile contain `gemspec' command
10
+ watch(/^.+\.gemspec/)
5
11
  end
@@ -1,4 +1,6 @@
1
1
  require "simple_rack_logger/version"
2
2
  require 'cgi'
3
3
 
4
- require 'simple_rack_logger/request_logger'
4
+ require 'simple_rack_logger/rack_logger'
5
+ require 'simple_rack_logger/request_logger'
6
+ require 'simple_rack_logger/error_logger'
@@ -0,0 +1,22 @@
1
+ #encoding: utf-8
2
+ module Rack
3
+
4
+ class ErrorLogger < RackLogger
5
+ attr_reader :logger
6
+
7
+ def initialize(app, logger, *filters)
8
+ super
9
+ end
10
+
11
+ def call(env)
12
+ begin
13
+ @app.call(env)
14
+ rescue => e
15
+ logger.error("#{e.message}\r\n#{e.backtrace.join("\r\n")}")
16
+ logger.flush
17
+ raise e
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ #encoding: utf-8
2
+ module Rack
3
+
4
+ class RackLogger
5
+ attr_reader :logger
6
+
7
+ def initialize(app, logger, *filters)
8
+ @app = app
9
+ @logger = logger
10
+ @filters = filters
11
+
12
+ def @logger.flush
13
+ # Chamando o flush diretamente, pois está demorando para descarregar a memória
14
+ # além de não ter a opção de executar
15
+ logdev = self.instance_variable_get(:@logdev)
16
+ logdev.instance_variable_get(:@dev).flush if logdev
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -1,20 +1,10 @@
1
1
  #encoding: utf-8
2
2
  module Rack
3
3
 
4
- class RequestLogger
5
- attr_reader :logger
4
+ class RequestLogger < RackLogger
6
5
 
7
6
  def initialize(app, logger, *filters)
8
- @app = app
9
- @logger = logger
10
- @filters = filters
11
-
12
- def @logger.flush
13
- # Chamando o flush diretamente, pois está demorando para descarregar a memória
14
- # além de não ter a opção de executar
15
- logdev = self.instance_variable_get(:@logdev)
16
- logdev.instance_variable_get(:@dev).flush if logdev
17
- end
7
+ super
18
8
  end
19
9
 
20
10
  def call(env)
@@ -1,3 +1,3 @@
1
1
  module SimpleRackLogger
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,16 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_rack_logger/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "simple-rack-logger"
8
- gem.version = SimpleRackLogger::VERSION
9
- gem.authors = ["Adriano Dadario"]
10
- gem.email = ["dadario@gmail.com"]
11
- gem.description = %q{A simple rack for log information from environment.}
12
- gem.summary = %q{For use in Rack application to log information from environment. Special from request data}
13
- gem.homepage = ""
7
+ gem.name = "simple-rack-logger"
8
+ gem.version = SimpleRackLogger::VERSION
9
+ gem.authors = ["Adriano Dadario"]
10
+ gem.email = ["dadario@gmail.com"]
11
+ gem.description = %q{A simple rack for log information from environment.}
12
+ gem.summary = %q{For use in Rack application to log information from environment. Special from request data}
13
+ gem.homepage = ""
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'simplecov'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'guard-rspec'
23
+ gem.add_development_dependency 'rb-inotify', '~> 0.8.8'
24
+ gem.add_development_dependency 'guard-bundler'
25
+ gem.add_development_dependency 'rack-test'
26
+
19
27
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::ErrorLogger do
4
+
5
+ let(:logger) { logger = double(Logger) }
6
+ let(:app) {
7
+ mock(Struct.new(:none))
8
+ }
9
+ let(:env) { { } }
10
+
11
+ subject {
12
+ Rack::ErrorLogger.new(app, logger)
13
+ }
14
+
15
+ it 'log exception when dispatched' do
16
+ app.should_receive(:call).and_throw(ArgumentError.new("forced error"))
17
+ logger.should_receive(:error).with(anything)
18
+
19
+ expect { subject.call(env) }.to raise_exception
20
+ end
21
+
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,8 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start
4
+
5
+
1
6
  require 'rspec'
2
7
  require 'rack/test'
3
8
  require 'logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-rack-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: simplecov
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rb-inotify
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.8
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.8
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack-test
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
14
110
  description: A simple rack for log information from environment.
15
111
  email:
16
112
  - dadario@gmail.com
@@ -25,9 +121,12 @@ files:
25
121
  - README.md
26
122
  - Rakefile
27
123
  - lib/simple-rack-logger.rb
124
+ - lib/simple_rack_logger/error_logger.rb
125
+ - lib/simple_rack_logger/rack_logger.rb
28
126
  - lib/simple_rack_logger/request_logger.rb
29
127
  - lib/simple_rack_logger/version.rb
30
128
  - simple-rack-logger.gemspec
129
+ - spec/simple_rack_logger/error_logger_spec.rb
31
130
  - spec/simple_rack_logger/request_logger_spec.rb
32
131
  - spec/spec_helper.rb
33
132
  homepage: ''
@@ -56,5 +155,6 @@ specification_version: 3
56
155
  summary: For use in Rack application to log information from environment. Special
57
156
  from request data
58
157
  test_files:
158
+ - spec/simple_rack_logger/error_logger_spec.rb
59
159
  - spec/simple_rack_logger/request_logger_spec.rb
60
160
  - spec/spec_helper.rb