logstash-input-file 4.1.16 → 4.2.2

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/LICENSE +199 -10
  4. data/docs/index.asciidoc +23 -7
  5. data/lib/filewatch/discoverer.rb +9 -8
  6. data/lib/filewatch/observing_base.rb +1 -12
  7. data/lib/filewatch/processor.rb +55 -0
  8. data/lib/filewatch/read_mode/handlers/base.rb +8 -6
  9. data/lib/filewatch/read_mode/handlers/read_file.rb +26 -8
  10. data/lib/filewatch/read_mode/handlers/read_zip_file.rb +63 -34
  11. data/lib/filewatch/read_mode/processor.rb +22 -36
  12. data/lib/filewatch/settings.rb +3 -2
  13. data/lib/filewatch/sincedb_collection.rb +23 -21
  14. data/lib/filewatch/stat/generic.rb +8 -13
  15. data/lib/filewatch/stat/windows_path.rb +7 -9
  16. data/lib/filewatch/tail_mode/handlers/delete.rb +2 -4
  17. data/lib/filewatch/tail_mode/processor.rb +47 -54
  18. data/lib/filewatch/watch.rb +12 -14
  19. data/lib/filewatch/watched_file.rb +25 -14
  20. data/lib/filewatch/watched_files_collection.rb +11 -74
  21. data/lib/jars/filewatch-1.0.1.jar +0 -0
  22. data/lib/logstash/inputs/delete_completed_file_handler.rb +5 -0
  23. data/lib/logstash/inputs/file.rb +32 -11
  24. data/logstash-input-file.gemspec +3 -2
  25. data/spec/filewatch/reading_spec.rb +60 -9
  26. data/spec/filewatch/rotate_spec.rb +2 -1
  27. data/spec/filewatch/settings_spec.rb +3 -0
  28. data/spec/filewatch/spec_helper.rb +13 -15
  29. data/spec/filewatch/tailing_spec.rb +14 -12
  30. data/spec/filewatch/watched_file_spec.rb +30 -0
  31. data/spec/filewatch/watched_files_collection_spec.rb +62 -8
  32. data/spec/helpers/spec_helper.rb +8 -0
  33. data/spec/inputs/file_read_spec.rb +154 -4
  34. data/spec/inputs/file_tail_spec.rb +3 -2
  35. metadata +21 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfc29a2b231d1d04667f304746d22fd1beec91cabeb8f6e05772395bc45e86a5
4
- data.tar.gz: 952de67a21b89420a91e787935ed0617a798a4c738632f0870d1c54c1162b110
3
+ metadata.gz: f8c11df0b47e51ceb5ebd37b3d16eb28acfef360aa976d4155752fffca3c0161
4
+ data.tar.gz: 297b2410e81e2f4228f59e459e486269238820b82f94a577068c53c87b9f2ea7
5
5
  SHA512:
6
- metadata.gz: 10b29419ea0fd69945fd0f9634d1a5c247516c14cec0b2d22e48155d4a53e71fd83551ffdd8df3dbff71e560bd5ba649deed94c549be92f582d05ec36c329ce1
7
- data.tar.gz: 16b160f663671c865c72a09b991c6f58bc915b29266d21ffa9f2c5130f62ad1feb469d9cb850f7997cd5bd6a8ae261e24920892ec27cc1ae6196dd4bf93e2b9a
6
+ metadata.gz: 639fbc4dd7b2f02977923726f997e8ecf2d57862ac6cf20dd284f2a1b55e0532eb0137d1b81be200afc10bc5a8f84c625e74211bb685a45099c4660b36ad15eb
7
+ data.tar.gz: ecee35a5081b61038e3f9052cbb447269d1a5def40f47fbbb1cb2f88f0ee509e98995f9441e7cf37329d505ee095087e58e6740856d21253ef59b1d40a25fa10
@@ -1,3 +1,23 @@
1
+ ## 4.2.2
2
+ - Fix: sincedb_clean_after not being respected [#276](https://github.com/logstash-plugins/logstash-input-file/pull/276)
3
+
4
+ ## 4.2.1
5
+ - Fix: skip sincedb eviction if read mode completion deletes file during flush [#273](https://github.com/logstash-plugins/logstash-input-file/pull/273)
6
+
7
+ ## 4.2.0
8
+ - Fix: watched files performance with huge filesets [#268](https://github.com/logstash-plugins/logstash-input-file/pull/268)
9
+ - Updated logging to include full traces in debug (and trace) levels
10
+
11
+ ## 4.1.18
12
+ - Fix: release watched files on completion (in read-mode) [#271](https://github.com/logstash-plugins/logstash-input-file/pull/271)
13
+
14
+ ## 4.1.17
15
+ - Added configuration setting `check_archive_validity` settings to enable
16
+ gzipped files verification, issue
17
+ [#261](https://github.com/logstash-plugins/logstash-input-file/issues/261)
18
+ - [DOC] Added clarification for settings available with `read` mode [#235](https://github.com/logstash-plugins/logstash-input-file/pull/235)
19
+ - [DOC] Rearranged text and fixed formatting for `mode` setting [266](https://github.com/logstash-plugins/logstash-input-file/pull/266)
20
+
1
21
  ## 4.1.16
2
22
  - Added configuration setting exit_after_read to read to EOF and terminate
3
23
  the input [#240](https://github.com/logstash-plugins/logstash-input-file/pull/240)
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -164,6 +164,7 @@ see <<plugins-{type}s-{plugin}-string_duration,string_duration>> for the details
164
164
  [cols="<,<,<",options="header",]
165
165
  |=======================================================================
166
166
  |Setting |Input type|Required
167
+ | <<plugins-{type}s-{plugin}-check_archive_validity>> |<<boolean,boolean>>|No
167
168
  | <<plugins-{type}s-{plugin}-close_older>> |<<number,number>> or <<plugins-{type}s-{plugin}-string_duration,string_duration>>|No
168
169
  | <<plugins-{type}s-{plugin}-delimiter>> |<<string,string>>|No
169
170
  | <<plugins-{type}s-{plugin}-discover_interval>> |<<number,number>>|No
@@ -191,6 +192,20 @@ input plugins.
191
192
 
192
193
  &nbsp;
193
194
 
195
+ [id="plugins-{type}s-{plugin}-check_archive_validity"]
196
+ ===== `check_archive_validity`
197
+
198
+ * Value type is <<boolean,boolean>>
199
+ * The default is `false`.
200
+
201
+ When set to `true`, this setting verifies that a compressed file is valid before
202
+ processing it. There are two passes through the file--one pass to
203
+ verify that the file is valid, and another pass to process the file.
204
+
205
+ Validating a compressed file requires more processing time, but can prevent a
206
+ corrupt archive from causing looping.
207
+
208
+
194
209
  [id="plugins-{type}s-{plugin}-close_older"]
195
210
  ===== `close_older`
196
211
 
@@ -355,16 +370,17 @@ A default of 4095 is set in internally.
355
370
 
356
371
  What mode do you want the file input to operate in. Tail a few files or
357
372
  read many content-complete files. Read mode now supports gzip file processing.
358
- If "read" is specified then the following other settings are ignored:
359
373
 
360
- . `start_position` (files are always read from the beginning)
361
- . `close_older` (files are automatically 'closed' when EOF is reached)
374
+ If `read` is specified, these settings can be used:
375
+
376
+ * `ignore_older` (older files are not processed)
377
+ * `file_completed_action` (what action should be taken when the file is processed)
378
+ * `file_completed_log_path` (which file should the completed file path be logged to)
362
379
 
363
- If "read" is specified then the following settings are heeded:
380
+ If `read` is specified, these settings are ignored:
364
381
 
365
- . `ignore_older` (older files are not processed)
366
- . `file_completed_action` (what action should be taken when the file is processed)
367
- . `file_completed_log_path` (which file should the completed file path be logged to)
382
+ * `start_position` (files are always read from the beginning)
383
+ * `close_older` (files are automatically 'closed' when EOF is reached)
368
384
 
369
385
  [id="plugins-{type}s-{plugin}-path"]
370
386
  ===== `path`
@@ -9,6 +9,8 @@ module FileWatch
9
9
  # associated with a sincedb entry if one can be found
10
10
  include LogStash::Util::Loggable
11
11
 
12
+ attr_reader :watched_files_collection
13
+
12
14
  def initialize(watched_files_collection, sincedb_collection, settings)
13
15
  @watching = Concurrent::Array.new
14
16
  @exclude = Concurrent::Array.new
@@ -37,8 +39,7 @@ module FileWatch
37
39
  @exclude.each do |pattern|
38
40
  if watched_file.pathname.basename.fnmatch?(pattern)
39
41
  if new_discovery
40
- logger.trace("Discoverer can_exclude?: #{watched_file.path}: skipping " +
41
- "because it matches exclude #{pattern}")
42
+ logger.trace("skipping file because it matches exclude", :path => watched_file.path, :pattern => pattern)
42
43
  end
43
44
  watched_file.unwatch
44
45
  return true
@@ -56,13 +57,13 @@ module FileWatch
56
57
  end
57
58
 
58
59
  def discover_any_files(path, ongoing)
59
- fileset = Dir.glob(path).select{|f| File.file?(f)}
60
- logger.trace("discover_files", "count" => fileset.size)
60
+ fileset = Dir.glob(path).select { |f| File.file?(f) }
61
+ logger.trace("discover_files", :count => fileset.size)
61
62
  fileset.each do |file|
62
- pathname = Pathname.new(file)
63
63
  new_discovery = false
64
- watched_file = @watched_files_collection.watched_file_by_path(file)
64
+ watched_file = @watched_files_collection.get(file)
65
65
  if watched_file.nil?
66
+ pathname = Pathname.new(file)
66
67
  begin
67
68
  path_stat = PathStatClass.new(pathname)
68
69
  rescue Errno::ENOENT
@@ -74,7 +75,7 @@ module FileWatch
74
75
  # if it already unwatched or its excluded then we can skip
75
76
  next if watched_file.unwatched? || can_exclude?(watched_file, new_discovery)
76
77
 
77
- logger.trace("discover_files handling:", "new discovery"=> new_discovery, "watched_file details" => watched_file.details)
78
+ logger.trace? && logger.trace("handling:", :new_discovery => new_discovery, :watched_file => watched_file.details)
78
79
 
79
80
  if new_discovery
80
81
  watched_file.initial_completed if ongoing
@@ -86,7 +87,7 @@ module FileWatch
86
87
  # associated with a different watched_file
87
88
  if @sincedb_collection.associate(watched_file)
88
89
  if watched_file.file_ignorable?
89
- logger.trace("Discoverer discover_files: #{file}: skipping because it was last modified more than #{@settings.ignore_older} seconds ago")
90
+ logger.trace("skipping file because it was last modified more than #{@settings.ignore_older} seconds ago", :path => file)
90
91
  # on discovery ignorable watched_files are put into the ignored state and that
91
92
  # updates the size from the internal stat
92
93
  # so the existing contents are not read.
@@ -62,8 +62,7 @@ module FileWatch
62
62
  @sincedb_collection = SincedbCollection.new(@settings)
63
63
  @sincedb_collection.open
64
64
  discoverer = Discoverer.new(watched_files_collection, @sincedb_collection, @settings)
65
- @watch = Watch.new(discoverer, watched_files_collection, @settings)
66
- @watch.add_processor build_specific_processor(@settings)
65
+ @watch = Watch.new(discoverer, build_specific_processor(@settings), @settings)
67
66
  end
68
67
 
69
68
  def watch_this(path)
@@ -84,15 +83,5 @@ module FileWatch
84
83
  # sincedb_write("shutting down")
85
84
  end
86
85
 
87
- # close_file(path) is to be used by external code
88
- # when it knows that it is completely done with a file.
89
- # Other files or folders may still be being watched.
90
- # Caution, once unwatched, a file can't be watched again
91
- # unless a new instance of this class begins watching again.
92
- # The sysadmin should rename, move or delete the file.
93
- def close_file(path)
94
- @watch.unwatch(path)
95
- sincedb_write
96
- end
97
86
  end
98
87
  end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require "logstash/util/loggable"
3
+ require 'concurrent/atomic/atomic_reference'
4
+
5
+ module FileWatch
6
+ class Processor
7
+ include LogStash::Util::Loggable
8
+
9
+ attr_reader :watch
10
+
11
+ def initialize(settings)
12
+ @settings = settings
13
+ @deletable_paths = Concurrent::AtomicReference.new []
14
+ end
15
+
16
+ def add_watch(watch)
17
+ @watch = watch
18
+ self
19
+ end
20
+
21
+ def clear_deletable_paths
22
+ @deletable_paths.get_and_set []
23
+ end
24
+
25
+ def add_deletable_path(path)
26
+ @deletable_paths.get << path
27
+ end
28
+
29
+ def restat(watched_file)
30
+ changed = watched_file.restat!
31
+ if changed
32
+ # the collection (when sorted by modified_at) needs to re-sort every time watched-file is modified,
33
+ # we can perform these update operation while processing files (stat interval) instead of having to
34
+ # re-sort the whole collection every time an entry is accessed
35
+ @watch.watched_files_collection.update(watched_file)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def error_details(error, watched_file)
42
+ details = { :path => watched_file.path,
43
+ :exception => error.class,
44
+ :message => error.message,
45
+ :backtrace => error.backtrace }
46
+ if logger.debug?
47
+ details[:file] = watched_file
48
+ else
49
+ details[:backtrace] = details[:backtrace].take(8) if details[:backtrace]
50
+ end
51
+ details
52
+ end
53
+
54
+ end
55
+ end
@@ -34,19 +34,21 @@ module FileWatch module ReadMode module Handlers
34
34
 
35
35
  def open_file(watched_file)
36
36
  return true if watched_file.file_open?
37
- logger.trace("opening #{watched_file.path}")
37
+ logger.trace? && logger.trace("opening", :path => watched_file.path)
38
38
  begin
39
39
  watched_file.open
40
- rescue
40
+ rescue => e
41
41
  # don't emit this message too often. if a file that we can't
42
42
  # read is changing a lot, we'll try to open it more often, and spam the logs.
43
43
  now = Time.now.to_i
44
44
  logger.trace("opening OPEN_WARN_INTERVAL is '#{OPEN_WARN_INTERVAL}'")
45
45
  if watched_file.last_open_warning_at.nil? || now - watched_file.last_open_warning_at > OPEN_WARN_INTERVAL
46
- logger.warn("failed to open #{watched_file.path}: #{$!.inspect}, #{$!.backtrace.take(3)}")
46
+ backtrace = e.backtrace
47
+ backtrace = backtrace.take(3) if backtrace && !logger.debug?
48
+ logger.warn("failed to open", :path => watched_file.path, :exception => e.class, :message => e.message, :backtrace => backtrace)
47
49
  watched_file.last_open_warning_at = now
48
50
  else
49
- logger.trace("suppressed warning for `failed to open` #{watched_file.path}: #{$!.inspect}")
51
+ logger.trace("suppressed warning (failed to open)", :path => watched_file.path, :exception => e.class, :message => e.message)
50
52
  end
51
53
  watched_file.watch # set it back to watch so we can try it again
52
54
  end
@@ -75,7 +77,7 @@ module FileWatch module ReadMode module Handlers
75
77
  watched_file.update_bytes_read(sincedb_value.position)
76
78
  else
77
79
  sincedb_value.set_watched_file(watched_file)
78
- logger.trace("add_or_update_sincedb_collection: switching from...", "watched_file details" => watched_file.details)
80
+ logger.trace("add_or_update_sincedb_collection: switching from", :watched_file => watched_file.details)
79
81
  watched_file.rotate_from(existing_watched_file)
80
82
  end
81
83
 
@@ -92,7 +94,7 @@ module FileWatch module ReadMode module Handlers
92
94
  def add_new_value_sincedb_collection(watched_file)
93
95
  sincedb_value = SincedbValue.new(0)
94
96
  sincedb_value.set_watched_file(watched_file)
95
- logger.trace("add_new_value_sincedb_collection: #{watched_file.path}", "position" => sincedb_value.position)
97
+ logger.trace("add_new_value_sincedb_collection:", :path => watched_file.path, :position => sincedb_value.position)
96
98
  sincedb_collection.set(watched_file.sincedb_key, sincedb_value)
97
99
  end
98
100
  end