logstash-logger 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +56 -5
- data/lib/logstash-logger.rb +1 -0
- data/lib/logstash-logger/configuration.rb +26 -0
- data/lib/logstash-logger/formatter.rb +2 -0
- data/lib/logstash-logger/version.rb +1 -1
- data/spec/configuration_spec.rb +27 -0
- data/spec/logger_spec.rb +16 -37
- data/spec/spec_helper.rb +6 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84c02ef7b86b7f3bbd3342b9978e6b172f9705ee
|
4
|
+
data.tar.gz: fb9fe50daa68b2c7f441b21816500baeb9c7e081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e759b59bb77b80ab16c15c99a22e33d33d81af4e151eaacd722fb6cf69648161f4e0053a5c54f97938a71c08dc63482e4ac5849fbf43854ca23be1520f8de8bd
|
7
|
+
data.tar.gz: 0da0fe1fd184fc8ddbe7ebb9a16c103496a9b8d9add08a1428ba707bcb794c87429fabce1a896e83d89b92452f467ccc9fd7b93fe7a6cfccbb76298a6ab73319
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.9.0
|
2
|
+
- Support for customizing the fields on all logged messages via configuration.
|
3
|
+
Fixes [#32](https://github.com/dwbutler/logstash-logger/pull/32).
|
4
|
+
Thanks [Chris Blatchley](https://github.com/chrisblatchley)!
|
5
|
+
|
1
6
|
## 0.8.0
|
2
7
|
- Support for logging to stderr. Fixes [#24](https://github.com/dwbutler/logstash-logger/pull/25).
|
3
8
|
Thanks [Jan Schulte](https://github.com/schultyy)!
|
data/README.md
CHANGED
@@ -76,11 +76,11 @@ such as Heroku where you may want to read configuration values from the environm
|
|
76
76
|
is `type://host:port/path`. Some sample URI configurations are given below.
|
77
77
|
|
78
78
|
```
|
79
|
-
udp://localhost:5228
|
80
|
-
tcp://localhost:5229
|
79
|
+
udp://localhost:5228
|
80
|
+
tcp://localhost:5229
|
81
81
|
unix:///tmp/socket
|
82
|
-
file:///path/to/file
|
83
|
-
redis://localhost:6379
|
82
|
+
file:///path/to/file
|
83
|
+
redis://localhost:6379
|
84
84
|
stdout:/
|
85
85
|
stderr:/
|
86
86
|
```
|
@@ -143,6 +143,44 @@ input {
|
|
143
143
|
}
|
144
144
|
```
|
145
145
|
|
146
|
+
## Custom Log Fields
|
147
|
+
|
148
|
+
`LogStashLogger` by default will log a JSON object with the format below.
|
149
|
+
|
150
|
+
```json
|
151
|
+
{
|
152
|
+
"message":"Some Message",
|
153
|
+
"@timestamp":"2015-01-29T10:43:32.196-05:00",
|
154
|
+
"@version":"1",
|
155
|
+
"severity":"INFO",
|
156
|
+
"host":"hostname"
|
157
|
+
}
|
158
|
+
```
|
159
|
+
|
160
|
+
Some applications may need to attach additional metadata to each message.
|
161
|
+
The `LogStash::Event` can be manipulated directly by specifying a `customize_event` block in the `LogStashLogger` configuration.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
config = LogStashLogger.configure do |config|
|
165
|
+
config.customize_event do |event|
|
166
|
+
event["other_field"] = "some_other_value"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
This configuration would result in the following output.
|
172
|
+
|
173
|
+
```json
|
174
|
+
{
|
175
|
+
"message": "Some Message",
|
176
|
+
"@timestamp": "2015-01-29T10:43:32.196-05:00",
|
177
|
+
"@version": "1",
|
178
|
+
"severity": "INFO",
|
179
|
+
"host": "hostname",
|
180
|
+
"other_field": "some_other_value"
|
181
|
+
}
|
182
|
+
```
|
183
|
+
|
146
184
|
## Rails Integration
|
147
185
|
|
148
186
|
Verified to work with both Rails 3 and 4.
|
@@ -273,7 +311,7 @@ config.logstash = [
|
|
273
311
|
|
274
312
|
Verified to work with:
|
275
313
|
|
276
|
-
* MRI Ruby 1.9.3, 2.0
|
314
|
+
* MRI Ruby 1.9.3, 2.0.x, 2.1.x, 2.2.x
|
277
315
|
* JRuby 1.7+
|
278
316
|
* Rubinius 2.2+
|
279
317
|
|
@@ -297,6 +335,18 @@ disadvantages of each type:
|
|
297
335
|
For a more detailed discussion of UDP vs TCP, I recommend reading this article:
|
298
336
|
[UDP vs. TCP](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/)
|
299
337
|
|
338
|
+
## Troubleshooting
|
339
|
+
|
340
|
+
### JSON::GeneratorError
|
341
|
+
Your application is probably attempting to log data that is not encoded in a valid way. When this happens, Ruby's
|
342
|
+
standard JSON library will raise an exception. You may be able to overcome this by swapping out a different JSON encoder
|
343
|
+
such as Oj. Use the [oj_mimic_json](https://github.com/ohler55/oj_mimic_json) gem to use Oj for JSON generation.
|
344
|
+
|
345
|
+
### No logs getting sent on Heroku
|
346
|
+
Heroku recommends installing the [rails_12factor](https://github.com/heroku/rails_12factor) so that logs get sent to STDOUT.
|
347
|
+
Unfortunately, this overrides LogStashLogger, preventing logs from being sent to their configured destination. The solution
|
348
|
+
is to remove `rails_12factor` from your Gemfile.
|
349
|
+
|
300
350
|
## Breaking changes
|
301
351
|
|
302
352
|
### Version 0.5+
|
@@ -328,6 +378,7 @@ logger = LogStashLogger.new('localhost', 5228, :tcp)
|
|
328
378
|
* [Arron Mabrey](https://github.com/arronmabrey)
|
329
379
|
* [Jan Schulte](https://github.com/schultyy)
|
330
380
|
* [Kurt Preston](https://github.com/KurtPreston)
|
381
|
+
* [Chris Blatchley](https://github.com/chrisblatchley)
|
331
382
|
|
332
383
|
## Contributing
|
333
384
|
|
data/lib/logstash-logger.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module LogStashLogger
|
2
|
+
class << self
|
3
|
+
def configure(&block)
|
4
|
+
@configuration = Configuration.new(&block) if block_given? || @configuration.nil?
|
5
|
+
@configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
alias :configuration :configure
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :customize_event_block
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
@customize_event_block = nil
|
16
|
+
|
17
|
+
yield self if block_given?
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def customize_event(&block)
|
22
|
+
@customize_event_block = block
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'logstash-logger'
|
2
|
+
|
3
|
+
describe LogStashLogger do
|
4
|
+
describe "#configure" do
|
5
|
+
it 'auto initializes' do
|
6
|
+
config = LogStashLogger.configure
|
7
|
+
expect(config).to be_a LogStashLogger::Configuration
|
8
|
+
expect(LogStashLogger.configuration).to eq(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe LogStashLogger::Configuration do
|
12
|
+
describe "#customize_event" do
|
13
|
+
it 'allows each LogStash::Event to be customized' do
|
14
|
+
config = LogStashLogger.configure do |config|
|
15
|
+
config.customize_event do |event|
|
16
|
+
event["test1"] = "response1"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
event = LogStash::Event.new({})
|
21
|
+
config.customize_event_block.call(event)
|
22
|
+
expect(event["test1"]).to eq("response1")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/logger_spec.rb
CHANGED
@@ -54,27 +54,14 @@ describe LogStashLogger do
|
|
54
54
|
|
55
55
|
it 'takes a string message as input and writes a logstash event' do
|
56
56
|
message = 'test'
|
57
|
-
|
58
|
-
expect(logdev).to receive(:write).and_call_original do |event|
|
59
|
-
expect(event).to be_a LogStash::Event
|
60
|
-
expect(event.host).to eql(hostname)
|
61
|
-
expect(event['message']).to eql(message)
|
62
|
-
expect(event['severity']).to eql('INFO')
|
63
|
-
end
|
64
|
-
|
65
57
|
logger.info(message)
|
66
58
|
|
59
|
+
expect(listener_event['severity']).to eql('INFO')
|
67
60
|
expect(listener_event['message']).to eq(message)
|
68
61
|
expect(listener_event['host']).to eq(hostname)
|
69
62
|
end
|
70
63
|
|
71
64
|
it 'takes a logstash-formatted json string as input and writes out a logstash event' do
|
72
|
-
expect(logdev).to receive(:write).and_call_original do |event|
|
73
|
-
expect(event).to be_a LogStash::Event
|
74
|
-
expect(event['message']).to eql(logstash_event['message'])
|
75
|
-
expect(event.host).to eql(hostname)
|
76
|
-
end
|
77
|
-
|
78
65
|
logger.info(logstash_event.to_json)
|
79
66
|
|
80
67
|
expect(listener_event['message']).to eq(logstash_event['message'])
|
@@ -82,18 +69,11 @@ describe LogStashLogger do
|
|
82
69
|
end
|
83
70
|
|
84
71
|
it 'takes a LogStash::Event as input and writes it out intact' do
|
85
|
-
expect(logdev).to receive(:write).and_call_original do |event|
|
86
|
-
expect(event).to be_a LogStash::Event
|
87
|
-
expect(event['message']).to eql(logstash_event['message'])
|
88
|
-
expect(event['severity']).to eql(logstash_event['severity'])
|
89
|
-
expect(event.timestamp).to eql(logstash_event.timestamp)
|
90
|
-
expect(event.host).to eql(hostname)
|
91
|
-
end
|
92
|
-
|
93
72
|
logger.warn(logstash_event)
|
94
73
|
|
95
74
|
expect(listener_event['message']).to eq(logstash_event['message'])
|
96
75
|
expect(listener_event['severity']).to eq(logstash_event['severity'])
|
76
|
+
expect(listener_event['@timestamp'].iso8601).to eq(logstash_event.timestamp.iso8601)
|
97
77
|
expect(listener_event['host']).to eq(hostname)
|
98
78
|
end
|
99
79
|
|
@@ -104,14 +84,6 @@ describe LogStashLogger do
|
|
104
84
|
'foo' => 'bar'
|
105
85
|
}
|
106
86
|
|
107
|
-
expect(logdev).to receive(:write).and_call_original do |event|
|
108
|
-
expect(event).to be_a LogStash::Event
|
109
|
-
expect(event['message']).to eql('test')
|
110
|
-
expect(event['severity']).to eql('INFO')
|
111
|
-
expect(event['foo']).to eql('bar')
|
112
|
-
expect(event.host).to eql(hostname)
|
113
|
-
end
|
114
|
-
|
115
87
|
logger.info(data.dup)
|
116
88
|
|
117
89
|
expect(listener_event['message']).to eq(data["message"])
|
@@ -124,16 +96,23 @@ describe LogStashLogger do
|
|
124
96
|
it 'takes any object as input and writes a logstash event' do
|
125
97
|
message = Time.now
|
126
98
|
|
127
|
-
expect(logdev).to receive(:write).and_call_original do |event|
|
128
|
-
expect(event).to be_a LogStash::Event
|
129
|
-
expect(event.host).to eql(hostname)
|
130
|
-
expect(event['message']).to eql(message.inspect)
|
131
|
-
expect(event['severity']).to eql('INFO')
|
132
|
-
end
|
133
|
-
|
134
99
|
logger.info(message)
|
135
100
|
|
136
101
|
expect(listener_event['message']).to eq(message.inspect)
|
102
|
+
expect(listener_event['host']).to eq(hostname)
|
103
|
+
expect(listener_event['severity']).to eq('INFO')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'allows event to be customized via configuration' do
|
107
|
+
LogStashLogger.configure do |config|
|
108
|
+
config.customize_event do |event|
|
109
|
+
event["test1"] = "response1"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
logger.info("test")
|
114
|
+
|
115
|
+
expect(listener_event["test1"]).to eq("response1")
|
137
116
|
end
|
138
117
|
|
139
118
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-event
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- gemfiles/rails_4.1.gemfile
|
158
158
|
- gemfiles/rails_4.2.gemfile
|
159
159
|
- lib/logstash-logger.rb
|
160
|
+
- lib/logstash-logger/configuration.rb
|
160
161
|
- lib/logstash-logger/device.rb
|
161
162
|
- lib/logstash-logger/device/base.rb
|
162
163
|
- lib/logstash-logger/device/connectable.rb
|
@@ -184,6 +185,7 @@ files:
|
|
184
185
|
- samples/tcp.conf
|
185
186
|
- samples/udp.conf
|
186
187
|
- samples/unix.conf
|
188
|
+
- spec/configuration_spec.rb
|
187
189
|
- spec/device/file_spec.rb
|
188
190
|
- spec/device/io_spec.rb
|
189
191
|
- spec/device/multi_delegator_spec.rb
|
@@ -219,11 +221,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
221
|
version: '0'
|
220
222
|
requirements: []
|
221
223
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.
|
224
|
+
rubygems_version: 2.2.2
|
223
225
|
signing_key:
|
224
226
|
specification_version: 4
|
225
227
|
summary: LogStash Logger for ruby
|
226
228
|
test_files:
|
229
|
+
- spec/configuration_spec.rb
|
227
230
|
- spec/device/file_spec.rb
|
228
231
|
- spec/device/io_spec.rb
|
229
232
|
- spec/device/multi_delegator_spec.rb
|