Module: Fluent::PluginId
- Included in:
- Fluent::Plugin::BareOutput, Fluent::Plugin::Filter, Fluent::Plugin::Input, Fluent::Plugin::MultiOutput, Fluent::Plugin::Output, Test::Driver::OwnerDummy
- Defined in:
- lib/fluent/plugin_id.rb
Constant Summary collapse
- @@configured_ids =
Set.new
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #initialize ⇒ Object
- #plugin_id ⇒ Object
- #plugin_id_configured? ⇒ Boolean
- #plugin_id_for_test? ⇒ Boolean
- #plugin_root_dir ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fluent/plugin_id.rb', line 28 def configure(conf) @id = conf['@id'] @_id_configured = !!@id # plugin id is explicitly configured by users (or not) if @id @id = @id.to_s if @@configured_ids.include?(@id) && !plugin_id_for_test? raise Fluent::ConfigError, "Duplicated plugin id `#{@id}`. Check whole configuration and fix it." end @@configured_ids.add(@id) end super end |
#initialize ⇒ Object
23 24 25 26 |
# File 'lib/fluent/plugin_id.rb', line 23 def initialize super @_plugin_root_dir = nil end |
#plugin_id ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin_id.rb', line 60 def plugin_id if instance_variable_defined?("@id") @id || "object:#{object_id.to_s(16)}" else "object:#{object_id.to_s(16)}" end end |
#plugin_id_configured? ⇒ Boolean
54 55 56 57 58 |
# File 'lib/fluent/plugin_id.rb', line 54 def plugin_id_configured? if instance_variable_defined?("@_id_configured") @_id_configured end end |
#plugin_id_for_test? ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin_id.rb', line 42 def plugin_id_for_test? caller_locations.each do |location| # Thread::Backtrace::Location#path returns base filename or absolute path. # #absolute_path returns absolute_path always. # https://bugs.ruby-lang.org/issues/12159 if location.absolute_path =~ /\/test_[^\/]+\.rb$/ # location.path =~ /test_.+\.rb$/ return true end end false end |
#plugin_root_dir ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin_id.rb', line 68 def plugin_root_dir return @_plugin_root_dir if @_plugin_root_dir return nil unless system_config.root_dir return nil unless plugin_id_configured? # Fluent::Plugin::Base#fluentd_worker_id dir = File.join(system_config.root_dir, "worker#{fluentd_worker_id}", plugin_id) FileUtils.mkdir_p(dir) unless Dir.exist?(dir) @_plugin_root_dir = dir.freeze dir end |