11# frozen_string_literal: true
2- require "systemd/journal"
3- require "fluent/plugin/input"
4- require "fluent/plugin/systemd/pos_writer"
5- require "fluent/plugin/systemd/entry_mutator"
2+
3+ require 'systemd/journal'
4+ require 'fluent/plugin/input'
5+ require 'fluent/plugin/systemd/pos_writer'
6+ require 'fluent/plugin/systemd/entry_mutator'
67
78module Fluent
89 module Plugin
10+ # Fluentd plugin for reading from the systemd journal
911 class SystemdInput < Input # rubocop:disable Metrics/ClassLength
10- Fluent ::Plugin . register_input ( " systemd" , self )
12+ Fluent ::Plugin . register_input ( ' systemd' , self )
1113
1214 helpers :timer , :storage
1315
14- DEFAULT_STORAGE_TYPE = " local"
16+ DEFAULT_STORAGE_TYPE = ' local'
1517
16- config_param :path , :string , default : " /var/log/journal"
18+ config_param :path , :string , default : ' /var/log/journal'
1719 config_param :filters , :array , default : [ ]
1820 config_param :pos_file , :string , default : nil , deprecated : "Use <storage> section with `persistent: true' instead"
1921 config_param :read_from_head , :bool , default : false
20- config_param :strip_underscores , :bool , default : false , deprecated : " Use <entry> section or `systemd_entry` " \
21- " filter plugin instead"
22+ config_param :strip_underscores , :bool , default : false , deprecated : ' Use <entry> section or `systemd_entry` ' \
23+ ' filter plugin instead'
2224 config_param :tag , :string
2325
2426 config_section :storage do
25- config_set_default :usage , " positions"
27+ config_set_default :usage , ' positions'
2628 config_set_default :@type , DEFAULT_STORAGE_TYPE
2729 config_set_default :persistent , false
2830 end
2931
30- config_section :entry , param_name : " entry_opts" , required : false , multi : false do
32+ config_section :entry , param_name : ' entry_opts' , required : false , multi : false do
3133 config_param :field_map , :hash , default : { }
3234 config_param :field_map_strict , :bool , default : false
3335 config_param :fields_strip_underscores , :bool , default : false
@@ -37,14 +39,12 @@ class SystemdInput < Input # rubocop:disable Metrics/ClassLength
3739 def configure ( conf )
3840 super
3941 @journal = nil
40- @pos_storage = PosWriter . new ( @pos_file , storage_create ( usage : " positions" ) )
42+ @pos_storage = PosWriter . new ( @pos_file , storage_create ( usage : ' positions' ) )
4143 # legacy strip_underscores backwards compatibility (legacy takes
4244 # precedence and is mutually exclusive with the entry block)
4345 mut_opts = @strip_underscores ? { fields_strip_underscores : true } : @entry_opts . to_h
4446 @mutator = SystemdEntryMutator . new ( **mut_opts )
45- if @mutator . field_map_strict && @mutator . field_map . empty?
46- log . warn ( "`field_map_strict` set to true with empty `field_map`, expect no fields" )
47- end
47+ @mutator . warnings . each { |warning | log . warn ( warning ) }
4848 end
4949
5050 def start
@@ -81,7 +81,7 @@ def seek
8181 rescue Systemd ::JournalError
8282 log . warn (
8383 "Could not seek to cursor #{ cursor } found in pos file: #{ @pos_storage . path } , " \
84- "falling back to reading from #{ read_from } " ,
84+ "falling back to reading from #{ read_from } "
8585 )
8686 seek_to ( read_from )
8787 end
@@ -120,7 +120,7 @@ def emit(entry)
120120 retries += 1
121121 sleep 1.5 **retries + rand ( 0 ..3 )
122122 retry
123- rescue => e
123+ rescue => e # rubocop:disable Style/RescueStandardError
124124 log . error ( "Exception emitting record: #{ e } " )
125125 end
126126
0 commit comments