logstash-output-file 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6b33f425aa5293480bcc2c4af3ee67be1939fd1
4
- data.tar.gz: 10169d9ac5138247aaa73aa83b7a89334e247e8f
3
+ metadata.gz: 6830f6d31289b7dde214ce06f996e209ee3db5e4
4
+ data.tar.gz: a2bc877e8c05e09d8fdb31a32b395a2297a07a61
5
5
  SHA512:
6
- metadata.gz: fa3b83b84a216b1867219d26a4c3d7145a72f79ca714e984cf45446579641649714b08e3a9dc703b7178fdc3575360ff0825a2bbb4f3f964758ee3b8e42838d2
7
- data.tar.gz: 7f6f55bf836b152b233fe3bced59566eebb6584b5c504697c51835099cb045a7d52dfce4e3685e546fe4abc9b333e81b1e619c15a6297ed1e572f148e9c717e3
6
+ metadata.gz: 798c79e80e9b82b9abe8181b7525bd53ff38e61a41e13739b2469041a8ba6ba0a3a782de8e35375919a665d23681d4495e126d578b3f7693d992cbb050281e92
7
+ data.tar.gz: 7cea0a4017d05aadac33325a9250a25bb2964b9bedd32365cf1764957293c6cadc67b012cf2110ebec21cd6bb787fafca0d83af4dd67f2f7eea2d92494ff2076
@@ -76,14 +76,23 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
76
76
 
77
77
  private
78
78
  def validate_path
79
- root_directory = @path.split(File::SEPARATOR).select { |item| !item.empty? }.shift
80
-
81
79
  if (root_directory =~ FIELD_REF) != nil
82
80
  @logger.error("File: The starting part of the path should not be dynamic.", :path => @path)
83
81
  raise LogStash::ConfigurationError.new("The starting part of the path should not be dynamic.")
84
82
  end
85
83
  end
86
84
 
85
+ private
86
+ def root_directory
87
+ parts = @path.split(File::SEPARATOR).select { |item| !item.empty? }
88
+ if Gem.win_platform?
89
+ # First part is the drive letter
90
+ parts[1]
91
+ else
92
+ parts.first
93
+ end
94
+ end
95
+
87
96
  public
88
97
  def receive(event)
89
98
  return unless output?(event)
@@ -99,6 +108,20 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
99
108
  write_event(file_output_path, output)
100
109
  end # def receive
101
110
 
111
+ public
112
+ def teardown
113
+ @logger.debug("Teardown: closing files")
114
+ @files.each do |path, fd|
115
+ begin
116
+ fd.close
117
+ @logger.debug("Closed file #{path}", :fd => fd)
118
+ rescue Exception => e
119
+ @logger.error("Exception while flushing and closing files.", :exception => e)
120
+ end
121
+ end
122
+ finished
123
+ end
124
+
102
125
  private
103
126
  def inside_file_root?(log_path)
104
127
  target_file = File.expand_path(log_path)
@@ -129,6 +152,7 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
129
152
  path =~ FIELD_REF
130
153
  end
131
154
 
155
+ private
132
156
  def format_message(event)
133
157
  if @message_format
134
158
  event.sprintf(@message_format)
@@ -137,24 +161,12 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
137
161
  end
138
162
  end
139
163
 
164
+ private
140
165
  def extract_file_root
141
166
  parts = File.expand_path(path).split(File::SEPARATOR)
142
167
  parts.take_while { |part| part !~ FIELD_REF }.join(File::SEPARATOR)
143
168
  end
144
169
 
145
- def teardown
146
- @logger.debug("Teardown: closing files")
147
- @files.each do |path, fd|
148
- begin
149
- fd.close
150
- @logger.debug("Closed file #{path}", :fd => fd)
151
- rescue Exception => e
152
- @logger.error("Exception while flushing and closing files.", :exception => e)
153
- end
154
- end
155
- finished
156
- end
157
-
158
170
  private
159
171
  def flush(fd)
160
172
  if flush_interval > 0
@@ -165,6 +177,7 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
165
177
  end
166
178
 
167
179
  # every flush_interval seconds or so (triggered by events, but if there are no events there's no point flushing files anyway)
180
+ private
168
181
  def flush_pending_files
169
182
  return unless Time.now - @last_flush_cycle >= flush_interval
170
183
  @logger.debug("Starting flush cycle")
@@ -176,6 +189,7 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
176
189
  end
177
190
 
178
191
  # every 10 seconds or so (triggered by events, but if there are no events there's no point closing files anyway)
192
+ private
179
193
  def close_stale_files
180
194
  now = Time.now
181
195
  return unless now - @last_stale_cleanup_cycle >= @stale_cleanup_interval
@@ -192,6 +206,7 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
192
206
  @last_stale_cleanup_cycle = now
193
207
  end
194
208
 
209
+ private
195
210
  def open(path)
196
211
  return @files[path] if @files.include?(path) and not @files[path].nil?
197
212
 
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-file'
4
- s.version = '0.1.3'
4
+ s.version = '0.1.4'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This output will write events to files on disk"
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -77,28 +77,25 @@ describe LogStash::Outputs::File do
77
77
  end
78
78
 
79
79
  describe "#register" do
80
+ let(:path) { '/%{name}' }
81
+ let(:output) { LogStash::Outputs::File.new({ "path" => path }) }
82
+
80
83
  it 'doesnt allow the path to start with a dynamic string' do
81
- path = '/%{name}'
82
- output = LogStash::Outputs::File.new({ "path" => path })
83
84
  expect { output.register }.to raise_error(LogStash::ConfigurationError)
85
+ output.teardown
84
86
  end
85
87
 
86
- it 'doesnt allow the root directory to have some dynamic part' do
87
- path = '/a%{name}/'
88
- output = LogStash::Outputs::File.new({ "path" => path })
89
- expect { output.register }.to raise_error(LogStash::ConfigurationError)
90
-
91
- path = '/a %{name}/'
92
- output = LogStash::Outputs::File.new({ "path" => path })
93
- expect { output.register }.to raise_error(LogStash::ConfigurationError)
94
-
95
- path = '/a- %{name}/'
96
- output = LogStash::Outputs::File.new({ "path" => path })
97
- expect { output.register }.to raise_error(LogStash::ConfigurationError)
98
-
99
- path = '/a- %{name}'
100
- output = LogStash::Outputs::File.new({ "path" => path })
101
- expect { output.register }.to raise_error(LogStash::ConfigurationError)
88
+ context 'doesnt allow the root directory to have some dynamic part' do
89
+ ['/a%{name}/',
90
+ '/a %{name}/',
91
+ '/a- %{name}/',
92
+ '/a- %{name}'].each do |test_path|
93
+ it "with path: #{test_path}" do
94
+ path = test_path
95
+ expect { output.register }.to raise_error(LogStash::ConfigurationError)
96
+ output.teardown
97
+ end
98
+ end
102
99
  end
103
100
 
104
101
  it 'allow to have dynamic part after the file root' do
@@ -136,6 +133,7 @@ describe LogStash::Outputs::File do
136
133
  error_file = File.join(path, config["filename_failure"])
137
134
 
138
135
  expect(File.exist?(error_file)).to eq(true)
136
+ output.teardown
139
137
  end
140
138
  end
141
139
 
@@ -154,6 +152,7 @@ describe LogStash::Outputs::File do
154
152
  output.receive(bad_event)
155
153
 
156
154
  expect(Dir.glob(File.join(path, "*")).size).to eq(2)
155
+ output.teardown
157
156
  end
158
157
  end
159
158
 
@@ -166,6 +165,7 @@ describe LogStash::Outputs::File do
166
165
  output.receive(bad_event)
167
166
 
168
167
  expect(Dir.glob(File.join(path, "*")).size).to eq(1)
168
+ output.teardown
169
169
  end
170
170
  end
171
171
  end
@@ -183,6 +183,7 @@ describe LogStash::Outputs::File do
183
183
 
184
184
  good_file = File.join(path, good_event['error'])
185
185
  expect(File.exist?(good_file)).to eq(true)
186
+ output.teardown
186
187
  end
187
188
  end
188
189
 
@@ -200,6 +201,7 @@ describe LogStash::Outputs::File do
200
201
  output.receive(good_event)
201
202
 
202
203
  expect(File.exist?(expected_path)).to eq(true)
204
+ output.teardown
203
205
  end
204
206
  end
205
207
 
@@ -221,6 +223,7 @@ describe LogStash::Outputs::File do
221
223
  output.receive(good_event)
222
224
 
223
225
  expect(File.exist?(expected_path)).to eq(true)
226
+ output.teardown
224
227
  end
225
228
  end
226
229
 
@@ -236,6 +239,7 @@ describe LogStash::Outputs::File do
236
239
 
237
240
  good_file = File.join(path, good_event['error'])
238
241
  expect(File.exist?(good_file)).to eq(true)
242
+ output.teardown
239
243
  end
240
244
  end
241
245
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
@@ -19,10 +20,7 @@ dependencies:
19
20
  - - <
20
21
  - !ruby/object:Gem::Version
21
22
  version: 2.0.0
22
- name: logstash
23
- prerelease: false
24
- type: :runtime
25
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: !ruby/object:Gem::Requirement
26
24
  requirements:
27
25
  - - '>='
28
26
  - !ruby/object:Gem::Version
@@ -30,34 +28,36 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
+ name: logstash-input-generator
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '>='
37
43
  - !ruby/object:Gem::Version
38
44
  version: '0'
39
- name: logstash-input-generator
40
45
  prerelease: false
41
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
42
49
  version_requirements: !ruby/object:Gem::Requirement
43
50
  requirements:
44
51
  - - '>='
45
52
  - !ruby/object:Gem::Version
46
53
  version: '0'
47
- - !ruby/object:Gem::Dependency
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements:
50
56
  - - '>='
51
57
  - !ruby/object:Gem::Version
52
58
  version: '0'
53
- name: logstash-devutils
54
59
  prerelease: false
55
60
  type: :development
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - '>='
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
61
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
62
62
  email: info@elasticsearch.com
63
63
  executables: []