logstash_rails 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.md +18 -4
- data/lib/logstash_rails/formatter.rb +13 -24
- data/lib/logstash_rails/version.rb +1 -1
- data/lib/logstash_rails.rb +0 -2
- data/spec/error_spec.rb +4 -26
- data/spec/subscription_spec.rb +0 -8
- metadata +4 -5
- data/lib/logstash_rails/formatter/process_action_action_controller.rb +0 -16
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,24 @@
|
|
2
2
|
|
3
3
|
Send Logstash events from a Rails application to Redis.
|
4
4
|
|
5
|
+
## Installation
|
5
6
|
|
6
|
-
|
7
|
+
In your applications Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'logstash_rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
For the latest version:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'logstash_rails', github: 'cmertz/logstash_rails'
|
17
|
+
```
|
18
|
+
|
19
|
+
Provide an initializer (e.g. config/initializers/logstash_rails.rb) for
|
20
|
+
specific configuration.
|
21
|
+
|
22
|
+
### Configuration
|
7
23
|
|
8
24
|
**LogstashRails.config** takes a redis connection, the redis key for the list
|
9
25
|
to push to and a flag that enables to catch all events (i.e. /.\*/)
|
@@ -30,6 +46,4 @@ end
|
|
30
46
|
|
31
47
|
## TODO
|
32
48
|
|
33
|
-
*
|
34
|
-
* reset config upon call to LogstashRails.config
|
35
|
-
* add formatter for more events (e.g. actionmailer, actionview, ...)
|
49
|
+
* more independent from Rails i.e. check defined?(Rails) and provide fallbacks (for logger and application name)
|
@@ -1,41 +1,30 @@
|
|
1
1
|
require 'logstash-event'
|
2
2
|
require 'socket'
|
3
|
-
require 'active_support/core_ext/string/inflections'
|
4
|
-
|
5
|
-
Dir["#{File.dirname(__FILE__)}/formatter/*.rb"].each do |file|
|
6
|
-
require file
|
7
|
-
end
|
8
3
|
|
9
4
|
module LogstashRails
|
10
5
|
module Formatter
|
11
6
|
|
12
|
-
def self.format(event_type,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
def self.format(event_type, start, finish, id, payload)
|
8
|
+
fields = {
|
9
|
+
process_id: $$,
|
10
|
+
host: Socket.gethostname
|
11
|
+
}
|
17
12
|
|
18
|
-
|
19
|
-
event = LogStash::Event.new
|
13
|
+
event = LogStash::Event.new(payload.merge!(fields))
|
20
14
|
|
21
|
-
event.message = event_type
|
22
15
|
event.timestamp = start
|
23
|
-
event.
|
24
|
-
|
25
|
-
event.fields['pid'] = $$
|
26
|
-
event.fields['id'] = id
|
27
|
-
|
28
|
-
formatter(event_type).format(event, payload)
|
16
|
+
event.message = event_type
|
17
|
+
event.source = application_name
|
29
18
|
|
30
19
|
event.to_json
|
31
20
|
end
|
32
21
|
|
33
|
-
|
34
|
-
const_get(event_type.gsub('.','_').camelize.to_sym)
|
35
|
-
end
|
22
|
+
private
|
36
23
|
|
37
|
-
def self.
|
38
|
-
|
24
|
+
def self.application_name
|
25
|
+
if defined?(Rails)
|
26
|
+
Rails.application.class.parent_name
|
27
|
+
end
|
39
28
|
end
|
40
29
|
|
41
30
|
end
|
data/lib/logstash_rails.rb
CHANGED
data/spec/error_spec.rb
CHANGED
@@ -1,38 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'mocha/setup'
|
2
3
|
|
3
4
|
describe 'error behaviour' do
|
4
5
|
|
5
|
-
before do
|
6
|
-
Redis::Connection::Memory.reset_all_databases
|
7
|
-
LogstashRails.config(redis)
|
8
|
-
ActiveSupport::Notifications.instrument("process_action.action_controller")
|
9
|
-
end
|
10
|
-
|
11
|
-
def redis
|
12
|
-
Redis.new
|
13
|
-
end
|
14
|
-
|
15
6
|
it 'logs exception traces to the Rails logger' do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def self.logger
|
20
|
-
@logger_mock ||= MiniTest::Mock.new
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Rails.logger.expect(:error, nil, [String])
|
7
|
+
logger = MiniTest::Mock.new
|
8
|
+
logger.expect(:error, nil, [String])
|
9
|
+
LogstashRails.stubs(:log).returns(logger)
|
25
10
|
|
26
11
|
LogstashRails.config(1)
|
27
12
|
|
28
13
|
ActiveSupport::Notifications.instrument("process_action.action_controller")
|
29
14
|
end
|
30
15
|
|
31
|
-
it 'survives weird event type names' do
|
32
|
-
skip
|
33
|
-
|
34
|
-
LogstashRails.config(redis)
|
35
|
-
ActiveSupport::Notifications.instrument("!!!")
|
36
|
-
end
|
37
|
-
|
38
16
|
end
|
data/spec/subscription_spec.rb
CHANGED
@@ -18,14 +18,6 @@ describe LogstashRails do
|
|
18
18
|
redis.lpop('logstash').wont_be_nil
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'does not handle unknown events' do
|
22
|
-
LogstashRails.config(redis)
|
23
|
-
|
24
|
-
ActiveSupport::Notifications.instrument("toto")
|
25
|
-
|
26
|
-
redis.lpop('logstash').must_be_nil
|
27
|
-
end
|
28
|
-
|
29
21
|
it 'does not handle events unless told to' do
|
30
22
|
LogstashRails.config(redis, 'logtstash', false)
|
31
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
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: 2013-06-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: logstash-event
|
@@ -74,7 +74,6 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- lib/logstash_rails.rb
|
76
76
|
- lib/logstash_rails/formatter.rb
|
77
|
-
- lib/logstash_rails/formatter/process_action_action_controller.rb
|
78
77
|
- lib/logstash_rails/version.rb
|
79
78
|
- logstash_rails.gemspec
|
80
79
|
- spec/config_spec.rb
|
@@ -97,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
96
|
version: '0'
|
98
97
|
segments:
|
99
98
|
- 0
|
100
|
-
hash: -
|
99
|
+
hash: -4390785812541147448
|
101
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
101
|
none: false
|
103
102
|
requirements:
|
@@ -106,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
105
|
version: '0'
|
107
106
|
segments:
|
108
107
|
- 0
|
109
|
-
hash: -
|
108
|
+
hash: -4390785812541147448
|
110
109
|
requirements: []
|
111
110
|
rubyforge_project:
|
112
111
|
rubygems_version: 1.8.25
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module LogstashRails
|
2
|
-
module Formatter
|
3
|
-
class ProcessActionActionController
|
4
|
-
|
5
|
-
def self.format(event, payload)
|
6
|
-
event.fields['http_verb'] = payload[:method]
|
7
|
-
event.fields['controller'] = payload[:controller]
|
8
|
-
event.fields['action'] = payload[:action]
|
9
|
-
event.fields['path'] = payload[:path]
|
10
|
-
event.fields['status'] = payload[:status]
|
11
|
-
event.fields['params'] = payload[:params]
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|