lapine 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89e5e020daab22750edbe3723c2fa8e1176f306b
4
- data.tar.gz: 5af0be7890edbb6b86c5721f53ddcda39cf74c1f
3
+ metadata.gz: df9e189850c444c60fc06be5f3054c162b518c81
4
+ data.tar.gz: 42e8387e0ea8d7928774149fda5be0c3710ffc05
5
5
  SHA512:
6
- metadata.gz: 6b4b37ad82d0ef7ffd18d52c8b5b0199815c9d99aa39d3fbc7bfea39427e1634c93294002d45f567580b0fc76a9648ae33238e17b8400e61b34f1cf5fb34c9e5
7
- data.tar.gz: 37379a5f8219d9eb3a043854f0c9723a552d5fbfdd999d4a0e5fd2f2988ccd42bd176e7108e78fe25381116753c394ca028d06424408237dfd783813aeaad01a
6
+ metadata.gz: 92b0b5edbc3bb1babdaf4d24a1dd3d50fe11233add45c8b5fcb6e0d97c9baf83a7e8510db06a948f6dd70dc9b1c788a643d6f0c2c4fafdd0160c6e24c50c039f
7
+ data.tar.gz: 3078a27dd0766c1af133801e4eb82f957847f099615221bcb8745cb17524cbc7b73334584fcc65fd7f19a62009f8ef35a44062b9bacdff3bd82ccb7cdc19ef9f
data/lib/lapine.rb CHANGED
@@ -2,6 +2,7 @@ require 'lapine/version'
2
2
  require 'lapine/configuration'
3
3
  require 'lapine/exchange'
4
4
  require 'lapine/publisher'
5
+ require 'lapine/annotated_logger'
5
6
 
6
7
  module Lapine
7
8
  class UndefinedConnection < StandardError; end
@@ -0,0 +1,70 @@
1
+ class AnnotatedLogger < Logger
2
+ attr_accessor :log_method_caller # if set will log ruby method name substring from where logging is called
3
+ attr_accessor :log_timestamps # if set will log timestamps up to millisecond
4
+ attr_accessor :colorize_logging # if set turns on colors (hint: turn off in production)
5
+
6
+ NUMBER_TO_COLOR_MAP = {"debug"=>'0;37', "info"=>'32', "warn"=>'33', "error"=>'31', "fatal"=>'31', "unknown"=>'37'}
7
+
8
+ def initialize *args
9
+ super *args
10
+ [:info, :debug, :warn, :error, :fatal].each { |m|
11
+ AnnotatedLogger.class_eval %Q!
12
+ def #{m} arg=nil, &block
13
+ level = "#{m}"
14
+ pid = "%.5d:" % $$
15
+ if block_given?
16
+ arg = yield
17
+ end
18
+ out = arg
19
+ out = out.gsub(/\n/, ' ') unless (level == "fatal" || out =~ /\\w+\\.rb:\\d+:in/m)
20
+ t = Time.now
21
+ l = log_message(t, pid, level, out)
22
+ super(l) if l
23
+ end
24
+ !
25
+ }
26
+ end
27
+
28
+ def log_message(t, pid, level, out)
29
+ color_on = color_off = sql_color_on = ""
30
+ if self.colorize_logging
31
+ color = NUMBER_TO_COLOR_MAP[level.to_s]
32
+ color_on = "\033[#{color}m"
33
+ sql_color_on = "\033[34m"
34
+ color_off = "\033[0m"
35
+ end
36
+ format_string = ""
37
+ format_values = []
38
+ if self.log_timestamps
39
+ format_string << "%s.%03d "
40
+ format_values << [t.strftime("%Y-%m-%d %H:%M:%S"), t.usec / 1000]
41
+ end
42
+ format_string << "%s #{color_on}%6.6s#{color_off} "
43
+ format_values << [pid, level]
44
+
45
+ if self.log_method_caller
46
+ file, line, method = caller_method
47
+ format_string << "|%-40.40s "
48
+ format_values << "#{File.basename(file)}:#{line}:#{method}"
49
+ end
50
+
51
+ format_string << "%s"
52
+ format_values << [out]
53
+ format_values.flatten!
54
+
55
+ format_string % format_values
56
+ end
57
+
58
+ def caller_method
59
+ parse_caller(caller(3).first)
60
+ end
61
+
62
+ def parse_caller(at)
63
+ if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
64
+ file = Regexp.last_match[1]
65
+ line = Regexp.last_match[2].to_i
66
+ method = Regexp.last_match[3]
67
+ [file, line, method]
68
+ end
69
+ end
70
+ end
@@ -1,7 +1,7 @@
1
1
  require 'amqp'
2
2
  require 'digest'
3
3
  require 'eventmachine'
4
- require 'logger'
4
+ require 'lapine/annotated_logger'
5
5
  require 'lapine/consumer/config'
6
6
  require 'lapine/consumer/connection'
7
7
  require 'lapine/consumer/environment'
@@ -16,6 +16,7 @@ module Lapine
16
16
  def initialize(argv)
17
17
  @argv = argv
18
18
  @message_count = 0
19
+ @running_message_count = 0
19
20
  end
20
21
 
21
22
  def run
@@ -32,15 +33,17 @@ module Lapine
32
33
  Lapine::Consumer::Dispatcher.new(clazz, payload, metadata, logger).dispatch
33
34
  end
34
35
 
35
- @message_count += 1 if config.debug?
36
-
36
+ if config.debug?
37
+ @message_count += 1
38
+ @running_message_count += 1
39
+ end
37
40
  metadata.ack
38
41
  end
39
42
  end
40
43
 
41
44
  if config.debug?
42
45
  EventMachine.add_periodic_timer(10) do
43
- logger.info "Lapine::Consumer messages processed=#{@message_count}"
46
+ logger.info "Lapine::Consumer messages processed=#{@message_count} running_count=#{@running_message_count}"
44
47
  @message_count = 0
45
48
  end
46
49
  end
@@ -58,7 +61,7 @@ module Lapine
58
61
  end
59
62
 
60
63
  def logger
61
- @logger ||= config.logfile ? Logger.new(config.logfile) : Logger.new(STDOUT)
64
+ @logger ||= config.logfile ? AnnotatedLogger.new(config.logfile) : AnnotatedLogger.new(STDOUT)
62
65
  end
63
66
 
64
67
  def queue_properties
@@ -1,3 +1,3 @@
1
1
  module Lapine
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -27,8 +27,14 @@ RSpec.describe Lapine::Consumer::Runner do
27
27
  ]
28
28
  end
29
29
 
30
+ after :each do
31
+ # Comment this out to see the log in the top level folder.
32
+ `rm -f #{logfile}`
33
+ end
34
+
35
+ let(:logfile) { File.expand_path('../../../../../lapine.log', __FILE__) }
30
36
  let(:config) { double('config',
31
- logfile: '/dev/null',
37
+ logfile: logfile,
32
38
  yaml_config: 'fakefil',
33
39
  connection_properties: connection_properties,
34
40
  require: [],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2014-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
@@ -172,6 +172,7 @@ files:
172
172
  - example/producer.rb
173
173
  - lapine.gemspec
174
174
  - lib/lapine.rb
175
+ - lib/lapine/annotated_logger.rb
175
176
  - lib/lapine/cli.rb
176
177
  - lib/lapine/configuration.rb
177
178
  - lib/lapine/consumer.rb
@@ -232,3 +233,4 @@ test_files:
232
233
  - spec/lib/lapine_spec.rb
233
234
  - spec/spec_helper.rb
234
235
  - spec/support/rspec_test_helper.rb
236
+ has_rdoc: