lib/fluent/plugin/in_systemd.rb in fluent-plugin-systemd-0.1.1.pre3 vs lib/fluent/plugin/in_systemd.rb in fluent-plugin-systemd-0.1.1
- old
+ new
@@ -17,11 +17,11 @@
config_param :tag, :string
def configure(conf)
super
@pos_writer = PosWriter.new(@pos_file)
- init_journal
+ @journal = nil
end
def start
super
@pos_writer.start
@@ -40,16 +40,23 @@
# make sure initial call to wait doesn't return :invalidate
# see https://github.com/ledbettj/systemd-journal/issues/70
@journal.wait(0)
@journal.filter(*@filters)
seek
+ true
+ rescue Systemd::JournalError => e
+ log.warn("#{e.class}: #{e.message} retrying in 1s")
+ false
end
def seek
seek_to(@pos_writer.cursor || read_from)
rescue Systemd::JournalError
- log.warn("Could not seek to cursor #{@pos_writer.cursor} found in pos file: #{@pos_writer.path}")
+ log.warn(
+ "Could not seek to cursor #{@pos_writer.cursor} found in pos file: #{@pos_writer.path}, " \
+ "falling back to reading from #{read_from}",
+ )
seek_to(read_from)
end
# according to https://github.com/ledbettj/systemd-journal/issues/64#issuecomment-271056644
# and https://bugs.freedesktop.org/show_bug.cgi?id=64614, after doing a seek(:tail),
@@ -68,9 +75,10 @@
def read_from
@read_from_head ? :head : :tail
end
def run
+ return unless @journal || init_journal
init_journal if @journal.wait(0) == :invalidate
watch do |entry|
begin
router.emit(@tag, Fluent::EventTime.from_time(entry.realtime_timestamp), formatted(entry))
rescue => e