amqp_logging 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,10 @@ You can change the configuration when creating the logger object by specifying a
15
15
 
16
16
  logger = AMQPLogging::Logger.new(config.log_path, logging_config)
17
17
  config.logger = logger
18
+
19
+ With Rails 3 you will need to modify this a bit, as config.log_path no longer has the desired effect:
20
+
21
+ config.logger = AMQPLogging::Logger.new(config.paths.log.to_a.first, logging_config)
18
22
 
19
23
  ==Routing Keys
20
24
 
data/lib/amqp_logging.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'bunny'
2
- require 'active_support'
2
+
3
+ begin
4
+ require 'active_support/time' # ActiveSupport 3.x
5
+ rescue LoadError
6
+ require 'active_support' # ActiveSupport 2.x
7
+ end
3
8
 
4
9
  module AMQPLogging
5
10
 
@@ -42,6 +47,7 @@ module AMQPLogging
42
47
  exchange.publish(msg, :key => routing_key)
43
48
  end
44
49
  rescue Exception => exception
50
+ reraise_expectation_errors!
45
51
  pause_amqp_logging(exception)
46
52
  ensure
47
53
  @fallback_logdev.write(msg)
@@ -75,10 +81,19 @@ module AMQPLogging
75
81
  end
76
82
 
77
83
  def bunny
78
- @bunny ||= Bunny.new(:host => @configuration[:host])
84
+ @bunny ||= Bunny.new(:host => configuration[:host])
79
85
  @bunny
80
86
  end
81
- end
82
87
 
88
+ if defined?(Mocha)
89
+ def reraise_expectation_errors! #:nodoc:
90
+ raise if $!.is_a?(Mocha::ExpectationError)
91
+ end
92
+ else
93
+ def reraise_expectation_errors! #:nodoc:
94
+ # noop
95
+ end
96
+ end
97
+ end
83
98
  end
84
99
 
@@ -73,23 +73,24 @@ class TheLogDeviceTest < Test::Unit::TestCase
73
73
  config = { :queue => "testqueue", :exchange => "testexchange", :host => "testhost", :shift_age => 4, :shift_size => 1338 }
74
74
  bunny_stub = stub_everything("bunny_stub")
75
75
  Bunny.expects(:new).with(:host => "testhost").returns(bunny_stub)
76
- bunny_stub.expects(:exchange).with(config[:exchange], :type => :topic).returns(stub("exchange stub"))
76
+ bunny_stub.expects(:exchange).with(config[:exchange], :type => :topic).returns(stub("exchange stub", :publish => true))
77
77
 
78
78
  logger = AMQPLogging::Logger.new(StringIO.new, config)
79
79
  logger.debug("foobar")
80
80
  end
81
81
 
82
82
  test "should publish the messages with the default routing key" do
83
+ message = "some stuff to log"
83
84
  exchange = mock()
84
- exchange.expects(:publish).with("msg\n", :key => "a_routing_key")
85
+ exchange.expects(:publish).with(anything, :key => "a_routing_key")
85
86
  AMQPLogging::AMQPLogDevice.any_instance.stubs(:exchange).returns(exchange)
86
- AMQPLogging::Logger.new(StringIO.new, {:routing_key => "a_routing_key"}).debug("msg")
87
+ AMQPLogging::Logger.new(StringIO.new, {:routing_key => "a_routing_key"}).debug(message)
87
88
  end
88
89
 
89
- test "should take a proc argument to generate the routing key" do
90
- key_generator = lambda {|msg| msg == "a message\n" }
90
+ test "should take a proc argument which gets the logline passed to generate the routing key" do
91
+ key_generator = lambda {|msg| !!(msg =~ /a message/) }
91
92
  exchange = mock()
92
- exchange.expects(:publish).with("a message\n", :key => "true")
93
+ exchange.expects(:publish).with(anything, :key => "true")
93
94
  AMQPLogging::AMQPLogDevice.any_instance.stubs(:exchange).returns(exchange)
94
95
  AMQPLogging::Logger.new(StringIO.new, {:routing_key => key_generator}).debug("a message")
95
96
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp_logging
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pascal Friederich
@@ -72,14 +72,14 @@ executables: []
72
72
  extensions: []
73
73
 
74
74
  extra_rdoc_files:
75
- - README.rdoc
75
+ - Readme.rdoc
76
76
  files:
77
77
  - lib/amqp_logging.rb
78
- - README.rdoc
78
+ - Readme.rdoc
79
79
  - test/amqp_logger_test.rb
80
80
  - test/test_helper.rb
81
81
  has_rdoc: true
82
- homepage: http://github.com/paukul/amqp-logging
82
+ homepage: http://github.com/paukul/amqp_logging
83
83
  licenses: []
84
84
 
85
85
  post_install_message: