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 +4 -4
- data/lib/lapine.rb +1 -0
- data/lib/lapine/annotated_logger.rb +70 -0
- data/lib/lapine/consumer/runner.rb +8 -5
- data/lib/lapine/version.rb +1 -1
- data/spec/lib/lapine/consumer/runner_spec.rb +7 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df9e189850c444c60fc06be5f3054c162b518c81
|
4
|
+
data.tar.gz: 42e8387e0ea8d7928774149fda5be0c3710ffc05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b0b5edbc3bb1babdaf4d24a1dd3d50fe11233add45c8b5fcb6e0d97c9baf83a7e8510db06a948f6dd70dc9b1c788a643d6f0c2c4fafdd0160c6e24c50c039f
|
7
|
+
data.tar.gz: 3078a27dd0766c1af133801e4eb82f957847f099615221bcb8745cb17524cbc7b73334584fcc65fd7f19a62009f8ef35a44062b9bacdff3bd82ccb7cdc19ef9f
|
data/lib/lapine.rb
CHANGED
@@ -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 '
|
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
|
-
|
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 ?
|
64
|
+
@logger ||= config.logfile ? AnnotatedLogger.new(config.logfile) : AnnotatedLogger.new(STDOUT)
|
62
65
|
end
|
63
66
|
|
64
67
|
def queue_properties
|
data/lib/lapine/version.rb
CHANGED
@@ -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:
|
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.
|
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-
|
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:
|