Class: Fluent::RouteOutput::Route

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/fluent/plugin/out_route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, router) ⇒ Route

Returns a new instance of Route.



32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/out_route.rb', line 32

def initialize(pattern, router)
  super()
  if !pattern || pattern.empty?
    pattern = '**'
  end
  @router = router
  @pattern = MatchPattern.create(pattern)
  @tag_cache = {}
end

Instance Attribute Details

#copyObject

TODO tag_transform regexp



30
31
32
# File 'lib/fluent/plugin/out_route.rb', line 30

def copy
  @copy
end

Instance Method Details

#configure(conf) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/out_route.rb', line 46

def configure(conf)
  super
  if conf['copy']
    @copy = true
  else
    @copy = false
  end
  if label_name = conf['@label']
    label = Fluent::Engine.root_agent.find_label(label_name)
    @router = label.event_router
  end
  if @remove_tag_prefix
    @prefix_match = /^#{Regexp.escape(@remove_tag_prefix)}\.?/
  else
    @prefix_match = //
  end
  if @add_tag_prefix
    @tag_prefix = "#{@add_tag_prefix}."
  else
    @tag_prefix = ""
  end
end

#copy?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fluent/plugin/out_route.rb', line 69

def copy?
  @copy
end

#emit(tag, es) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/out_route.rb', line 73

def emit(tag, es)
  ntag = @tag_cache[tag]
  unless ntag
    ntag = tag.sub(@prefix_match, @tag_prefix)
    if @tag_cache.size < 1024  # TODO size limit
      @tag_cache[tag] = ntag
    end
  end
  @router.emit_stream(ntag, es)
end

#match?(tag) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fluent/plugin/out_route.rb', line 42

def match?(tag)
  @pattern.match(tag)
end