lib/fluent/plugin/in_systemd.rb in fluent-plugin-systemd-1.0.0.rc2 vs lib/fluent/plugin/in_systemd.rb in fluent-plugin-systemd-1.0.0.rc3
- old
+ new
@@ -1,7 +1,21 @@
# frozen_string_literal: true
+# Copyright 2015-2018 Edward Robinson
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
require 'systemd/journal'
require 'fluent/plugin/input'
require 'fluent/plugin/systemd/entry_mutator'
module Fluent
@@ -114,19 +128,18 @@
def formatted(entry)
@mutator.run(entry)
end
- def watch
- while @journal.move_next
- begin
- yield @journal.current_entry
- rescue Systemd::JournalError => e
- log.warn("Error Parsing Journal: #{e.class}: #{e.message}")
- next
- end
- @pos_storage.put(:journal, @journal.cursor)
- end
+ def watch(&block)
+ yield_current_entry(&block) while @journal.move_next
+ end
+
+ def yield_current_entry
+ yield @journal.current_entry
+ @pos_storage.put(:journal, @journal.cursor)
+ rescue Systemd::JournalError => e
+ log.warn("Error reading from Journal: #{e.class}: #{e.message}")
end
end
end
end