Class: Fluent::TextParser::JSONishParser

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

Instance Method Summary collapse

Constructor Details

#initializeJSONishParser

Returns a new instance of JSONishParser.



44
45
46
# File 'lib/fluent/plugin/parser_jsonish.rb', line 44

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



48
49
50
51
52
53
54
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
99
100
101
102
103
# File 'lib/fluent/plugin/parser_jsonish.rb', line 48

def configure(conf)

  if conf['time_format'] and not conf['time_format'].nil?
    # 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.delete('time_format')
    # This has to be set to string when time_format is set.
    # Deleting it without deleting time_type will leave an
    # invalid configuration.
    tmp_time_type = conf.delete('time_type')
  end

  super(conf)

  # Overwrite the time parser unless the time_type is set
  # to something other than string.
  if not tmp_time_type.nil? and tmp_time_type == 'string'
      @time_parser = StdFormatTimeParser.new(tmp_time_format)
      # If these values are not restored, fluent will not
      # show the value in trace/debug output.
      conf['time_type'] = tmp_time_type
      @time_type = tmp_time_type
      conf['time_format'] = tmp_time_format
      @time_format = tmp_time_format
  elsif tmp_time_format.nil?
      # The v1.0 time parser has a way to use the Time class
      # method iso8601, but I would still to be able to access
      # any available Time methods in a generic way.
      @time_parser = StdFormatTimeParser.new('iso8601')
      @time_type = 'string'
      @time_format = 'iso8601'
  end
  @mutex = Mutex.new

  @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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fluent/plugin/parser_jsonish.rb', line 105

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