Class: Fluent::TextParser::JSONishParser

Inherits:
JSONParser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_jsonish.rb

Instance Method Summary collapse

Constructor Details

#initializeJSONishParser



51
52
53
# File 'lib/fluent/plugin/parser_jsonish.rb', line 51

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fluent/plugin/parser_jsonish.rb', line 55

def configure(conf)

  if conf['time_format']
    # Remove the time_format key before the super call
    # so the it does as little as possible as possible
    # (ie. less that we'll have to override).
    tmp_time_format = conf['time_format']
    conf.delete('time_format')
  end

  super(conf)

  @time_parser = StdFormatTimeParser.new(tmp_time_format)
  @mutex = Mutex.new

  # This may look stupid (it actually is really stupid),
  # but this *must* be set back to a non-null string
  # prior to the return, since the superclass parser
  # method checks for this and them implements its
  # own ad hoc parser, in-line.  This is a necessary
  # kludge to bypass a more egregious kludge.
  @time_format = 'ignore_me'

  @transforms = []

  @maps.each do |elem|
    if elem.is_a?(Array)
      @transforms << [ Regexp.new(elem[0]), elem[1] ]
    elsif elem.is_a?(String)
      if elem == 'slashes'
        @transforms << [ Regexp.new("\\\\"), "\\\\\\" ]
      elsif elem == 'nulls'
        @null_maps.each do |e|
          @transforms << [ Regexp.new(sprintf(e[0],@null_pattern)), e[1] ]
        end
      else
        raise ConfigError, "Unknown transform #{elem}."
      end
    else
      raise ConfigError, "Unknown transform data type."
    end
  end

end

#parse(text) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fluent/plugin/parser_jsonish.rb', line 100

def parse(text)

  full_message = @add_full_message ? text : nil

  @transforms.each do |args|
    text.gsub!(*args)
  end

  super(text) do |time,record|
    if @message_key
      record['message'] = record[@message_key]
    end

    if full_message
      record['full_message'] = full_message
    end

    @move_keys.map do |k,v|
      record[v] = record.delete(k)
    end
    record.delete(nil)

    yield time, record
  end

end