captivity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,29 @@
1
1
  = captivity
2
2
 
3
- Captivity is a simplistick Rack middleware for capturing and logging exceptions. It is a replacement for the CommonLogger
4
- middleware which I found lacking and abandoned. It's compatible with any Logger implementation.
3
+ Captivity is a simplistick Rack middleware for capturing and logging exceptions and requests.
4
+ It atcs like a wrapper for the Rack CommonLogger, but it fixes it's incompatibility
5
+ with the Logger interface (request logs will be logged as INFO messages).
6
+
7
+ == Usage
8
+
9
+ In your rackup file, grab a logger (you can configure it dynamically) and feed it to the Captivity middleware
10
+
11
+ logger = if ENV['RACK_ENV'] == 'production'
12
+ Le.new('<YOUR_LOGENTRIES_KEY>', 'myserver/webapp1')
13
+ else
14
+ Logger.new(STDERR)
15
+ end
16
+ logger.level = Logger::INFO
17
+ use Captivity, logger
18
+
19
+ Then, in your app, use the passed Logger object by using the "captivity.logger" env variable:
20
+
21
+ def logger
22
+ env["captivity.logger"]
23
+ end
24
+
25
+ ...
26
+ logger.warn("Bad things are-a happenin'!")
5
27
 
6
28
  == Contributing to captivity
7
29
 
data/captivity.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "captivity"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
12
- s.date = "2012-07-08"
12
+ s.date = "2013-04-11"
13
13
  s.description = "A simple logging wrapper for Rack"
14
14
  s.email = "me@julik.nl"
15
15
  s.extra_rdoc_files = [
data/lib/captivity.rb CHANGED
@@ -3,7 +3,7 @@ require 'logger'
3
3
  require 'rack/commonlogger'
4
4
 
5
5
  class Captivity
6
- VERSION = '0.0.1'
6
+ VERSION = '0.0.2'
7
7
 
8
8
  # Rack::CommonLogger is so ingeniously put together that
9
9
  # it does not honor the standard logger levels, it uses #write.
@@ -25,6 +25,7 @@ class Captivity
25
25
  # the defined Logger object in the "captivity.logger" of the env hash
26
26
  def call(env)
27
27
  env["captivity.logger"] = @logger
28
+ set_active_record_logger_if_present!
28
29
  @app.call(env)
29
30
  rescue StandardError, LoadError, SyntaxError => exception
30
31
  log_exception(exception)
@@ -34,6 +35,12 @@ class Captivity
34
35
 
35
36
  private
36
37
 
38
+ def set_active_record_logger_if_present!
39
+ if defined?(ActiveRecord)
40
+ ActiveRecord::Base.logger = @logger
41
+ end
42
+ end
43
+
37
44
  def log_exception(exception)
38
45
  @logger.fatal(
39
46
  "\t#{exception.class} (#{exception.message}):\n " +
@@ -34,4 +34,19 @@ class TestCaptivity < Test::Unit::TestCase
34
34
  assert_match /GET \/boom/, stream.string
35
35
  end
36
36
 
37
+ def test_captivity_injects_env_variable
38
+ stream = StringIO.new
39
+
40
+ @app = Rack::Builder.app do
41
+ use Captivity, stream
42
+ inner = lambda do |env|
43
+ env["captivity.logger"].error("Variable is present!")
44
+ [200, {'Content-Type' => 'text/plain'}, 'OK']
45
+ end
46
+ run inner
47
+ end
48
+
49
+ get '/boom'
50
+ assert_match /Variable is present/, stream.string
51
+ end
37
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captivity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-08 00:00:00.000000000 Z
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  segments:
93
93
  - 0
94
- hash: -1991590435747958573
94
+ hash: 2974344955014551893
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements: