logstash-logger 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +100 -25
- data/lib/logstash-logger/device.rb +7 -0
- data/lib/logstash-logger/device/base.rb +2 -0
- data/lib/logstash-logger/device/connectable.rb +50 -0
- data/lib/logstash-logger/device/file.rb +23 -0
- data/lib/logstash-logger/device/redis.rb +70 -0
- data/lib/logstash-logger/device/socket.rb +2 -41
- data/lib/logstash-logger/device/stdout.rb +2 -0
- data/lib/logstash-logger/device/tcp.rb +3 -1
- data/lib/logstash-logger/device/udp.rb +1 -0
- data/lib/logstash-logger/device/unix.rb +18 -0
- data/lib/logstash-logger/railtie.rb +8 -0
- data/lib/logstash-logger/version.rb +1 -1
- data/logstash-logger.gemspec +2 -0
- data/samples/file.conf +11 -0
- data/samples/redis.conf +12 -0
- data/samples/unix.conf +11 -0
- data/spec/device/file_spec.rb +15 -0
- data/spec/device/redis_spec.rb +22 -0
- data/spec/device/tcp_spec.rb +2 -0
- data/spec/device/unix_spec.rb +22 -0
- data/spec/spec_helper.rb +6 -0
- metadata +43 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ce22d1b662dce1b8438a6760bc747a141e810b8
|
4
|
+
data.tar.gz: ec33c1bf4b20ebeb54271d5b307d77c6f3195c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8832f5370c049bfaa6ebe74f91ba716c42e43ad0d2b1d31a6fc2c0379005f18d9a0a2842271af50958c39488671d38986e271683df8c6d684c6a3077f6c2bfb9
|
7
|
+
data.tar.gz: fa9188fd5ff3e1e3585c112bb35258cd4dce9a141e208b3c6123dc91a5db54f0d0c54d682ced533d4f3516090d97666245ec9b301c978f0d4756526f4233c8bb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.6.0
|
2
|
+
- Support for logging to a file.
|
3
|
+
- Support for logging to a Redis list.
|
4
|
+
- Support for logging to a local Unix socket.
|
5
|
+
- Railtie supports file logger, using default log path and `config.autoflush_log` configuration.
|
6
|
+
- All `LogStashLogger` types now support a `sync` option, which controls if each message is automatically flushed.
|
7
|
+
|
1
8
|
## 0.5.0
|
2
9
|
- Support for tagged logging. The interface was extracted from `ActiveSupport::TaggedLogging`
|
3
10
|
and outputs to the `tags` key. (Thanks [pctj101](https://github.com/pctj101)!)
|
data/README.md
CHANGED
@@ -7,10 +7,12 @@ writing to a file or syslog since logstash can receive the structured data direc
|
|
7
7
|
|
8
8
|
## Features
|
9
9
|
|
10
|
-
*
|
10
|
+
* Can write directly to logstash over a UDP or TCP/SSL connection.
|
11
|
+
* Can write to a file, Redis, a unix socket, or stdout.
|
11
12
|
* Always writes in logstash JSON format.
|
12
|
-
* Logger can take a string message, a hash, a LogStash::Event
|
13
|
+
* Logger can take a string message, a hash, a `LogStash::Event`, or a JSON string as input.
|
13
14
|
* Events are automatically populated with message, timestamp, host, and severity.
|
15
|
+
* Easily integrates with Rails via configuration.
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
@@ -28,11 +30,6 @@ Or install it yourself as:
|
|
28
30
|
|
29
31
|
## Basic Usage
|
30
32
|
|
31
|
-
First set up a logstash agent to receive input over a UDP or TCP port.
|
32
|
-
Then in ruby, create a `LogStashLogger` that writes to that port.
|
33
|
-
|
34
|
-
The logger accepts a string message, a JSON string, a hash, or a `LogStash::Event`.
|
35
|
-
|
36
33
|
```ruby
|
37
34
|
require 'logstash-logger'
|
38
35
|
|
@@ -40,8 +37,13 @@ require 'logstash-logger'
|
|
40
37
|
logger = LogStashLogger.new(port: 5228)
|
41
38
|
|
42
39
|
# Specify host and type (UDP or TCP) explicitly
|
43
|
-
udp_logger = LogStashLogger.new(host: 'localhost', port: 5228
|
44
|
-
tcp_logger = LogStashLogger.new(host: 'localhost', port: 5229
|
40
|
+
udp_logger = LogStashLogger.new(type: :udp, host: 'localhost', port: 5228)
|
41
|
+
tcp_logger = LogStashLogger.new(type: :tcp, host: 'localhost', port: 5229)
|
42
|
+
|
43
|
+
# Other types of loggers
|
44
|
+
file_logger = LogStashLogger.new(type: :file, path: 'log/development.log', sync: true)
|
45
|
+
unix_logger = LogStashLogger.new(type: :unix, path: '/tmp/sock')
|
46
|
+
redis_logger = LogStashLogger.new(type: :redis)
|
45
47
|
stdout_logger = LogStashLogger.new(type: :stdout)
|
46
48
|
|
47
49
|
# The following messages are written to UDP port 5228:
|
@@ -65,8 +67,9 @@ logger.tagged('foo') { logger.fatal('bar') }
|
|
65
67
|
|
66
68
|
## Logstash Configuration
|
67
69
|
|
68
|
-
In order for
|
69
|
-
configure and run a
|
70
|
+
In order for logstash to correctly receive and parse the events, you will need to
|
71
|
+
configure and run a listener that uses the `json_lines` codec. For example, to receive
|
72
|
+
events over UDP on port 5228:
|
70
73
|
|
71
74
|
```ruby
|
72
75
|
input {
|
@@ -80,14 +83,6 @@ input {
|
|
80
83
|
|
81
84
|
See the [samples](https://github.com/dwbutler/logstash-logger/tree/master/samples) directory for more configuration samples.
|
82
85
|
|
83
|
-
## UDP vs TCP
|
84
|
-
Should you write to a UDP or TCP listener? It depends on your specific needs, but most applications should use the default (UDP).
|
85
|
-
|
86
|
-
* UDP is faster because it's asynchronous (fire-and-forget). However, this means that log messages could get dropped. This is okay for most applications.
|
87
|
-
* TCP verifies that every message has been received via two-way communication . This could slow your app down to a crawl if the TCP listener is under heavy load.
|
88
|
-
|
89
|
-
For a more detailed discussion of UDP vs TCP, I recommend reading this article: [UDP vs. TCP](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/)
|
90
|
-
|
91
86
|
## SSL
|
92
87
|
|
93
88
|
If you are using TCP then there is the option of adding an SSL certificate to the options hash on initialize.
|
@@ -127,21 +122,82 @@ Verified to work with both Rails 3 and 4.
|
|
127
122
|
|
128
123
|
Add the following to your `config/environments/production.rb`:
|
129
124
|
|
125
|
+
### Common Options
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
# Optional, Rails sets the default to :info
|
129
|
+
config.log_level = :debug
|
130
|
+
|
131
|
+
# Optional, Rails 4 defaults to true in development and false in production
|
132
|
+
config.autoflush_log = true
|
133
|
+
```
|
134
|
+
|
135
|
+
### UDP
|
130
136
|
```ruby
|
131
137
|
# Optional, defaults to '0.0.0.0'
|
132
138
|
config.logstash.host = 'localhost'
|
133
139
|
|
134
|
-
#
|
140
|
+
# Optional, defaults to :udp.
|
141
|
+
config.logstash.type = :udp
|
142
|
+
|
143
|
+
# Required, the port to connect to
|
135
144
|
config.logstash.port = 5228
|
145
|
+
```
|
136
146
|
|
137
|
-
|
138
|
-
|
147
|
+
### TCP
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
# Optional, defaults to '0.0.0.0'
|
151
|
+
config.logstash.host = 'localhost'
|
152
|
+
|
153
|
+
# Required, the port to connect to
|
154
|
+
config.logstash.port = 5228
|
155
|
+
|
156
|
+
# Required
|
157
|
+
config.logstash.type = :tcp
|
139
158
|
|
140
|
-
# Optional, enables SSL
|
159
|
+
# Optional, enables SSL
|
141
160
|
config.logstash.ssl_enable = true
|
161
|
+
```
|
142
162
|
|
143
|
-
|
144
|
-
|
163
|
+
### Unix Socket
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
# Required
|
167
|
+
config.logstash.type = :unix
|
168
|
+
|
169
|
+
# Required
|
170
|
+
config.logstash.path = '/tmp/sock'
|
171
|
+
```
|
172
|
+
|
173
|
+
### Redis
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
# Required
|
177
|
+
config.logstash.type = :redis
|
178
|
+
|
179
|
+
# Optional, will default to the 'logstash' list
|
180
|
+
config.logstash.list = 'logstash'
|
181
|
+
|
182
|
+
# All other options are passed in to the Redis client
|
183
|
+
# Supported options include host, port, path, password, url
|
184
|
+
# Example:
|
185
|
+
|
186
|
+
# Optional, Redis will default to localhost
|
187
|
+
config.logstash.host = 'localhost'
|
188
|
+
|
189
|
+
# Optional, Redis will default to port 6379
|
190
|
+
config.logstash.port = 6379
|
191
|
+
```
|
192
|
+
|
193
|
+
### File
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
# Required
|
197
|
+
config.logstash.type = :file
|
198
|
+
|
199
|
+
# Optional, defaults to Rails log path
|
200
|
+
config.logstash.path = 'log/production.log'
|
145
201
|
```
|
146
202
|
|
147
203
|
By default, every Rails log message will be written to logstash in `LogStash::Event` JSON format.
|
@@ -164,6 +220,25 @@ Verified to work with:
|
|
164
220
|
|
165
221
|
Ruby 1.8.7 is not supported.
|
166
222
|
|
223
|
+
|
224
|
+
## What type of logger should I use?
|
225
|
+
|
226
|
+
It depends on your specific needs, but most applications should use the default (UDP). Here are the advantages and
|
227
|
+
disadvantages of each type:
|
228
|
+
|
229
|
+
* UDP is faster than TCP because it's asynchronous (fire-and-forget). However, this means that log messages could get dropped.
|
230
|
+
This is okay for many applications.
|
231
|
+
* TCP verifies that every message has been received via two-way communication. It also supports SSL for secure transmission
|
232
|
+
of log messages over a network. This could slow your app down to a crawl if the TCP listener is under heavy load.
|
233
|
+
* A file is simple to use, but you will have to worry about log rotation and running out of disk space.
|
234
|
+
* Writing to a Unix socket is faster than writing to a TCP or UDP port, but only works locally.
|
235
|
+
* Writing to Redis is good for distributed setups that generate tons of logs. However, you will have another moving part and
|
236
|
+
have to worry about Redis running out of memory.
|
237
|
+
* Writing to stdout is only recommended for debugging purposes.
|
238
|
+
|
239
|
+
For a more detailed discussion of UDP vs TCP, I recommend reading this article:
|
240
|
+
[UDP vs. TCP](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/)
|
241
|
+
|
167
242
|
## Breaking changes
|
168
243
|
|
169
244
|
### Version 0.5+
|
@@ -5,9 +5,13 @@ module LogStashLogger
|
|
5
5
|
DEFAULT_TYPE = :udp
|
6
6
|
|
7
7
|
autoload :Base, 'logstash-logger/device/base'
|
8
|
+
autoload :Connectable, 'logstash-logger/device/connectable'
|
8
9
|
autoload :Socket, 'logstash-logger/device/socket'
|
9
10
|
autoload :UDP, 'logstash-logger/device/udp'
|
10
11
|
autoload :TCP, 'logstash-logger/device/tcp'
|
12
|
+
autoload :Unix, 'logstash-logger/device/unix'
|
13
|
+
autoload :Redis, 'logstash-logger/device/redis'
|
14
|
+
autoload :File, 'logstash-logger/device/file'
|
11
15
|
autoload :Stdout, 'logstash-logger/device/stdout'
|
12
16
|
|
13
17
|
def self.new(opts)
|
@@ -20,6 +24,9 @@ module LogStashLogger
|
|
20
24
|
case type
|
21
25
|
when :udp then UDP
|
22
26
|
when :tcp then TCP
|
27
|
+
when :unix then Unix
|
28
|
+
when :file then File
|
29
|
+
when :redis then Redis
|
23
30
|
when :stdout then Stdout
|
24
31
|
else fail ArgumentError, 'Invalid type'
|
25
32
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module LogStashLogger
|
2
|
+
module Device
|
3
|
+
class Connectable < Base
|
4
|
+
def write(message)
|
5
|
+
with_connection do
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def flush
|
11
|
+
return unless connected?
|
12
|
+
with_connection do
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_io
|
18
|
+
with_connection do
|
19
|
+
@io
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def connected?
|
24
|
+
!!@io
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
# Implemented by subclasses
|
30
|
+
def connect
|
31
|
+
fail NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
def reconnect
|
35
|
+
@io = nil
|
36
|
+
connect
|
37
|
+
end
|
38
|
+
|
39
|
+
# Ensure the block is executed with a valid connection
|
40
|
+
def with_connection(&block)
|
41
|
+
connect unless @io
|
42
|
+
yield
|
43
|
+
rescue => e
|
44
|
+
warn "#{self.class} - #{e.class} - #{e.message}"
|
45
|
+
close
|
46
|
+
@io = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module LogStashLogger
|
4
|
+
module Device
|
5
|
+
class File < Base
|
6
|
+
def initialize(opts)
|
7
|
+
super
|
8
|
+
@path = opts[:path] || fail(ArgumentError, "Path is required")
|
9
|
+
open
|
10
|
+
end
|
11
|
+
|
12
|
+
def open
|
13
|
+
unless ::File.exist? ::File.dirname @path
|
14
|
+
::FileUtils.mkdir_p ::File.dirname @path
|
15
|
+
end
|
16
|
+
|
17
|
+
@io = ::File.open @path, ::File::WRONLY | ::File::APPEND | ::File::CREAT
|
18
|
+
@io.binmode
|
19
|
+
@io.sync = self.sync
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'stud/buffer'
|
3
|
+
|
4
|
+
module LogStashLogger
|
5
|
+
module Device
|
6
|
+
class Redis < Connectable
|
7
|
+
include Stud::Buffer
|
8
|
+
|
9
|
+
DEFAULT_LIST = 'logstash'
|
10
|
+
|
11
|
+
attr_accessor :list
|
12
|
+
|
13
|
+
def initialize(opts)
|
14
|
+
super
|
15
|
+
@list = opts.delete(:list) || DEFAULT_LIST
|
16
|
+
@redis_options = opts
|
17
|
+
|
18
|
+
@batch_events = opts.fetch(:batch_events, 50)
|
19
|
+
@batch_timeout = opts.fetch(:batch_timeout, 5)
|
20
|
+
|
21
|
+
buffer_initialize max_items: @batch_events, max_interval: @batch_timeout
|
22
|
+
end
|
23
|
+
|
24
|
+
def connect
|
25
|
+
@io = ::Redis.new(@redis_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def reconnect
|
29
|
+
@io.client.reconnect
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_connection
|
33
|
+
connect unless @io
|
34
|
+
yield
|
35
|
+
rescue ::Redis::InheritedError
|
36
|
+
reconnect
|
37
|
+
retry
|
38
|
+
rescue => e
|
39
|
+
warn "#{self.class} - #{e.class} - #{e.message}"
|
40
|
+
@io = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def write(message)
|
44
|
+
buffer_receive message, @list
|
45
|
+
buffer_flush(force: true) if @sync
|
46
|
+
end
|
47
|
+
|
48
|
+
def close
|
49
|
+
buffer_flush(final: true)
|
50
|
+
@io && @io.quit
|
51
|
+
rescue => e
|
52
|
+
warn "#{self.class} - #{e.class} - #{e.message}"
|
53
|
+
ensure
|
54
|
+
@io = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def flush(*args)
|
58
|
+
if args.empty?
|
59
|
+
buffer_flush
|
60
|
+
else
|
61
|
+
messages, list = *args
|
62
|
+
with_connection do
|
63
|
+
@io.rpush(list, messages)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -2,55 +2,16 @@ require 'socket'
|
|
2
2
|
|
3
3
|
module LogStashLogger
|
4
4
|
module Device
|
5
|
-
class Socket <
|
5
|
+
class Socket < Connectable
|
6
6
|
DEFAULT_HOST = '0.0.0.0'
|
7
7
|
|
8
8
|
attr_reader :host, :port
|
9
9
|
|
10
10
|
def initialize(opts)
|
11
|
+
super
|
11
12
|
@port = opts[:port] || fail(ArgumentError, "Port is required")
|
12
13
|
@host = opts[:host] || DEFAULT_HOST
|
13
14
|
end
|
14
|
-
|
15
|
-
def write(message)
|
16
|
-
with_connection do
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def flush
|
22
|
-
return unless connected?
|
23
|
-
with_connection do
|
24
|
-
super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_io
|
29
|
-
with_connection do
|
30
|
-
@io
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def connected?
|
35
|
-
!!@io
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
# Implemented by TCP and UDP devices
|
41
|
-
def connect
|
42
|
-
fail NotImplementedError
|
43
|
-
end
|
44
|
-
|
45
|
-
# Ensure the block is executed with a valid connection
|
46
|
-
def with_connection(&block)
|
47
|
-
connect unless @io
|
48
|
-
yield
|
49
|
-
rescue => e
|
50
|
-
warn "#{self.class} - #{e.class} - #{e.message}"
|
51
|
-
close
|
52
|
-
@io = nil
|
53
|
-
end
|
54
15
|
end
|
55
16
|
end
|
56
17
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module LogStashLogger
|
4
|
+
module Device
|
5
|
+
class Unix < Connectable
|
6
|
+
def initialize(opts={})
|
7
|
+
super
|
8
|
+
@path = opts[:path] || fail(ArgumentError, "Path is required")
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect
|
12
|
+
@io = ::UNIXSocket.new(@path).tap do |socket|
|
13
|
+
socket.sync = sync unless sync.nil?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -6,6 +6,14 @@ module LogStashLogger
|
|
6
6
|
|
7
7
|
logger_options = app.config.logstash
|
8
8
|
|
9
|
+
if logger_options.type == :file
|
10
|
+
logger_options.path ||= app.config.paths["log"].first
|
11
|
+
end
|
12
|
+
|
13
|
+
if app.config.respond_to?(:autoflush_log)
|
14
|
+
logger_options.sync = app.config.autoflush_log
|
15
|
+
end
|
16
|
+
|
9
17
|
logger = LogStashLogger.new(logger_options)
|
10
18
|
|
11
19
|
logger.level = ::Logger.const_get(app.config.log_level.to_s.upcase)
|
data/logstash-logger.gemspec
CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.add_runtime_dependency 'logstash-event', '~> 1.2'
|
22
|
+
gem.add_runtime_dependency 'stud'
|
22
23
|
|
23
24
|
gem.add_development_dependency 'rails'
|
25
|
+
gem.add_development_dependency 'redis'
|
24
26
|
gem.add_development_dependency 'rspec', '>= 3'
|
25
27
|
gem.add_development_dependency 'rake'
|
26
28
|
gem.add_development_dependency 'pry'
|
data/samples/file.conf
ADDED
data/samples/redis.conf
ADDED
data/samples/unix.conf
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'logstash-logger'
|
2
|
+
|
3
|
+
describe LogStashLogger::Device::File do
|
4
|
+
include_context 'device'
|
5
|
+
|
6
|
+
it "writes to a file" do
|
7
|
+
expect(file_device.to_io).to be_a ::File
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when path is not specified" do
|
11
|
+
it "raises an exception" do
|
12
|
+
expect { described_class.new }.to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'logstash-logger'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
describe LogStashLogger::Device::Redis do
|
5
|
+
include_context 'device'
|
6
|
+
|
7
|
+
let(:redis) { double("Redis") }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
allow(Redis).to receive(:new) { redis }
|
11
|
+
allow(redis).to receive(:connect)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "writes to a Redis list" do
|
15
|
+
expect(redis).to receive(:rpush)
|
16
|
+
redis_device.write "foo"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "defaults the Redis list to 'logstash'" do
|
20
|
+
expect(redis_device.list).to eq('logstash')
|
21
|
+
end
|
22
|
+
end
|
data/spec/device/tcp_spec.rb
CHANGED
@@ -8,6 +8,8 @@ describe LogStashLogger::Device::TCP do
|
|
8
8
|
|
9
9
|
before(:each) do
|
10
10
|
allow(TCPSocket).to receive(:new) { tcp_socket }
|
11
|
+
allow(tcp_socket).to receive(:sync=)
|
12
|
+
|
11
13
|
allow(OpenSSL::SSL::SSLSocket).to receive(:new) { ssl_socket }
|
12
14
|
allow(ssl_socket).to receive(:connect)
|
13
15
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'logstash-logger'
|
2
|
+
|
3
|
+
describe LogStashLogger::Device::Unix do
|
4
|
+
include_context 'device'
|
5
|
+
|
6
|
+
let(:unix_socket) { double("UNIXSocket") }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow(::UNIXSocket).to receive(:new) { unix_socket }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "writes to a local unix socket" do
|
13
|
+
expect(unix_socket).to receive(:write)
|
14
|
+
unix_device.write('foo')
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when path is not specified" do
|
18
|
+
it "raises an exception" do
|
19
|
+
expect { described_class.new }.to raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -38,4 +38,10 @@ RSpec.shared_context 'device' do
|
|
38
38
|
let(:udp_device) { LogStashLogger::Device.new(type: :udp, port: port) }
|
39
39
|
let(:tcp_device) { LogStashLogger::Device.new(type: :tcp, port: port) }
|
40
40
|
let(:ssl_tcp_device) { LogStashLogger::Device.new(type: :tcp, port: port, ssl_enable: true) }
|
41
|
+
let(:unix_device) { LogStashLogger::Device.new(type: :unix, path: '/tmp/logstash') }
|
42
|
+
|
43
|
+
let(:file) { Tempfile.new('test') }
|
44
|
+
let(:file_device) { LogStashLogger::Device.new(type: :file, path: file.path)}
|
45
|
+
|
46
|
+
let(:redis_device) { LogStashLogger::Device.new(type: :redis, sync: true) }
|
41
47
|
end
|
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.6.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: 2014-06-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-event
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stud
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,10 +158,14 @@ files:
|
|
130
158
|
- lib/logstash-logger.rb
|
131
159
|
- lib/logstash-logger/device.rb
|
132
160
|
- lib/logstash-logger/device/base.rb
|
161
|
+
- lib/logstash-logger/device/connectable.rb
|
162
|
+
- lib/logstash-logger/device/file.rb
|
163
|
+
- lib/logstash-logger/device/redis.rb
|
133
164
|
- lib/logstash-logger/device/socket.rb
|
134
165
|
- lib/logstash-logger/device/stdout.rb
|
135
166
|
- lib/logstash-logger/device/tcp.rb
|
136
167
|
- lib/logstash-logger/device/udp.rb
|
168
|
+
- lib/logstash-logger/device/unix.rb
|
137
169
|
- lib/logstash-logger/formatter.rb
|
138
170
|
- lib/logstash-logger/logger.rb
|
139
171
|
- lib/logstash-logger/railtie.rb
|
@@ -142,13 +174,19 @@ files:
|
|
142
174
|
- logstash-logger.gemspec
|
143
175
|
- samples/example.crt
|
144
176
|
- samples/example.key
|
177
|
+
- samples/file.conf
|
178
|
+
- samples/redis.conf
|
145
179
|
- samples/ssl.conf
|
146
180
|
- samples/tcp.conf
|
147
181
|
- samples/udp.conf
|
182
|
+
- samples/unix.conf
|
183
|
+
- spec/device/file_spec.rb
|
184
|
+
- spec/device/redis_spec.rb
|
148
185
|
- spec/device/socket_spec.rb
|
149
186
|
- spec/device/stdout_spec.rb
|
150
187
|
- spec/device/tcp_spec.rb
|
151
188
|
- spec/device/udp_spec.rb
|
189
|
+
- spec/device/unix_spec.rb
|
152
190
|
- spec/device_spec.rb
|
153
191
|
- spec/logger_spec.rb
|
154
192
|
- spec/rails_spec.rb
|
@@ -179,10 +217,13 @@ signing_key:
|
|
179
217
|
specification_version: 4
|
180
218
|
summary: LogStash Logger for ruby
|
181
219
|
test_files:
|
220
|
+
- spec/device/file_spec.rb
|
221
|
+
- spec/device/redis_spec.rb
|
182
222
|
- spec/device/socket_spec.rb
|
183
223
|
- spec/device/stdout_spec.rb
|
184
224
|
- spec/device/tcp_spec.rb
|
185
225
|
- spec/device/udp_spec.rb
|
226
|
+
- spec/device/unix_spec.rb
|
186
227
|
- spec/device_spec.rb
|
187
228
|
- spec/logger_spec.rb
|
188
229
|
- spec/rails_spec.rb
|