logstasher 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +12 -0
- data/lib/logstasher.rb +7 -3
- data/lib/logstasher/version.rb +1 -1
- data/spec/lib/logstasher/log_subscriber_spec.rb +4 -0
- data/spec/lib/logstasher_spec.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjdkMjE3MDE0ZWEzMDQ3Y2VkOTdjNjllODg4Y2UzNzZkOTg1Yjc5MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTcyYTI4MDY1NTY0YjJhMzg3MjlkMTM4NjQ0N2VmNTRmNTJlZGNmNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTEzNmI5ZmU0MTJhZWYzN2IwMzhlMTJhYjc1NGU0OTA3MGQzNWI4Mjc4ODNl
|
10
|
+
NTU0NGJiMTc3NmNlM2E4ZDliOTMzYmMyYmQ0ZWUxY2E1NWE0ZWJlZWZlNTZl
|
11
|
+
NTFjZjQxOWIwNzQ0NzhkNzE0NDYyYzg1YWEwYzdmNjBhYWM1MTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTllN2NlMzFkNDI4MTNjN2QxNjRhNjI1ZTk5NTAxZjc2ZTYwNDdiODgwZTAz
|
14
|
+
NDU1MDUwYjM4NTBkZDc1MzlkMzc0MmU1NzQ4MGY3ZDNlMzNjZDliYmM3MWM3
|
15
|
+
YjgzMmU1MzdkNzM0MTkxNmRiNGNmMjdjZmU5Zjk0MGRhYjU3MmE=
|
data/README.md
CHANGED
@@ -59,6 +59,18 @@ In your Gemfile:
|
|
59
59
|
# This line is optional if you do not want to suppress app logs in your <environment>.log
|
60
60
|
config.logstasher.suppress_app_log = false
|
61
61
|
|
62
|
+
## Logging params hash
|
63
|
+
|
64
|
+
Logstasher can be configured to log the contents of the params hash. When enabled, the contents of the params hash (minus the ActionController internal params)
|
65
|
+
will be added to the log as a deep hash. This can cause conflicts within the Elasticsearch mappings though, so should be enabled with care. Conflicts will occur
|
66
|
+
if different actions (or even different applications logging to the same Elasticsearch cluster) use the same params key, but with a different data type (e.g. a
|
67
|
+
string vs. a hash). This can lead to lost log entries. Enabling this can also significantly increase the size of the Elasticsearch indexes.
|
68
|
+
|
69
|
+
To enable this, add the following to your `<environment>.rb`
|
70
|
+
|
71
|
+
# Enable logging of controller params
|
72
|
+
config.logstasher.log_controller_parameters = true
|
73
|
+
|
62
74
|
## Adding custom fields to the log
|
63
75
|
|
64
76
|
Since some fields are very specific to your application for e.g. *user_name*, so it is left upto you, to add them. Here's how to add those fields to the logs:
|
data/lib/logstasher.rb
CHANGED
@@ -6,7 +6,7 @@ require 'active_support/ordered_options'
|
|
6
6
|
|
7
7
|
module LogStasher
|
8
8
|
extend self
|
9
|
-
attr_accessor :logger, :enabled
|
9
|
+
attr_accessor :logger, :enabled, :log_controller_parameters
|
10
10
|
|
11
11
|
def remove_existing_log_subscriptions
|
12
12
|
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
|
@@ -33,8 +33,11 @@ module LogStasher
|
|
33
33
|
def add_default_fields_to_payload(payload, request)
|
34
34
|
payload[:ip] = request.remote_ip
|
35
35
|
payload[:route] = "#{request.params[:controller]}##{request.params[:action]}"
|
36
|
-
|
37
|
-
self.
|
36
|
+
self.custom_fields += [:ip, :route]
|
37
|
+
if self.log_controller_parameters
|
38
|
+
payload[:parameters] = payload[:params].except(*ActionController::LogSubscriber::INTERNAL_PARAMS)
|
39
|
+
self.custom_fields += [:parameters]
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
def add_custom_fields(&block)
|
@@ -52,6 +55,7 @@ module LogStasher
|
|
52
55
|
self.logger = app.config.logstasher.logger || new_logger("#{Rails.root}/log/logstash_#{Rails.env}.log")
|
53
56
|
self.logger.level = app.config.logstasher.log_level || Logger::WARN
|
54
57
|
self.enabled = true
|
58
|
+
self.log_controller_parameters = !! app.config.logstasher.log_controller_parameters
|
55
59
|
end
|
56
60
|
|
57
61
|
def suppress_app_logs(app)
|
data/lib/logstasher/version.rb
CHANGED
@@ -14,8 +14,12 @@ describe LogStasher::RequestLogSubscriber do
|
|
14
14
|
}
|
15
15
|
before do
|
16
16
|
LogStasher.logger = logger
|
17
|
+
LogStasher.log_controller_parameters = true
|
17
18
|
LogStasher.custom_fields = []
|
18
19
|
end
|
20
|
+
after do
|
21
|
+
LogStasher.log_controller_parameters = false
|
22
|
+
end
|
19
23
|
|
20
24
|
let(:subscriber) {LogStasher::RequestLogSubscriber.new}
|
21
25
|
let(:event) {
|
data/spec/lib/logstasher_spec.rb
CHANGED
@@ -38,8 +38,10 @@ describe LogStasher do
|
|
38
38
|
let(:request) { double(:params => params, :remote_ip => '10.0.0.1')}
|
39
39
|
after do
|
40
40
|
LogStasher.custom_fields = []
|
41
|
+
LogStasher.log_controller_parameters = false
|
41
42
|
end
|
42
43
|
it 'appends default parameters to payload' do
|
44
|
+
LogStasher.log_controller_parameters = true
|
43
45
|
LogStasher.custom_fields = []
|
44
46
|
LogStasher.add_default_fields_to_payload(payload, request)
|
45
47
|
payload[:ip].should == '10.0.0.1'
|
@@ -47,6 +49,13 @@ describe LogStasher do
|
|
47
49
|
payload[:parameters].should == {'a' => '1', 'b' => 2}
|
48
50
|
LogStasher.custom_fields.should == [:ip, :route, :parameters]
|
49
51
|
end
|
52
|
+
|
53
|
+
it 'does not include parameters when not configured to' do
|
54
|
+
LogStasher.custom_fields = []
|
55
|
+
LogStasher.add_default_fields_to_payload(payload, request)
|
56
|
+
payload.should_not have_key(:parameters)
|
57
|
+
LogStasher.custom_fields.should == [:ip, :route]
|
58
|
+
end
|
50
59
|
end
|
51
60
|
|
52
61
|
describe '.append_custom_params' do
|
@@ -59,7 +68,7 @@ describe LogStasher do
|
|
59
68
|
|
60
69
|
describe '.setup' do
|
61
70
|
let(:logger) { double }
|
62
|
-
let(:logstasher_config) { double(:logger => logger,:log_level => 'warn') }
|
71
|
+
let(:logstasher_config) { double(:logger => logger,:log_level => 'warn',:log_controller_parameters => nil) }
|
63
72
|
let(:config) { double(:logstasher => logstasher_config) }
|
64
73
|
let(:app) { double(:config => config) }
|
65
74
|
before do
|
@@ -74,6 +83,7 @@ describe LogStasher do
|
|
74
83
|
LogStasher.setup(app)
|
75
84
|
LogStasher.enabled.should be_true
|
76
85
|
LogStasher.custom_fields.should == []
|
86
|
+
LogStasher.log_controller_parameters.should == false
|
77
87
|
end
|
78
88
|
end
|
79
89
|
|