Class: Fluent::GlusterfsLogInput
- Inherits:
-
TailInput
- Object
- TailInput
- Fluent::GlusterfsLogInput
- Defined in:
- lib/fluent/plugin/in_glusterfs_log.rb
Instance Method Summary collapse
-
#initialize ⇒ GlusterfsLogInput
constructor
A new instance of GlusterfsLogInput.
- #parse_line(line) ⇒ Object
Constructor Details
#initialize ⇒ GlusterfsLogInput
Returns a new instance of GlusterfsLogInput.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fluent/plugin/in_glusterfs_log.rb', line 12 def initialize super # NOTE: Here you can specify if output lines into the event stream # that fluentd fails to parse or else. (:default => true) @handle_parse_failure ||= true # NOTE: Here you can configure field names of JSON. # YOU SHOULD NOT SPECIFY EACH STRING AS NIL. field ||= { :date => 'date', :time => 'time', :time_usec => 'time_usec', :log_level => 'log_level', :source_file_name => 'source_file_name', :source_line => 'source_line', :function_name => 'function_name', :component_name => 'component_name', :message => 'message', :hostname => 'hostname' } # NOTE: Here you can set an optional hostname in string which is # output into the JSON event logs. (:default => Socket.gethostname) @hostname ||= Socket.gethostname # NOTE: NEVER MODIFY FOLLOWING INITIALIZATIONS. @field = init_field(field) @time_format = init_time_format @regex = init_regex end |
Instance Method Details
#parse_line(line) ⇒ Object
44 45 46 47 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 |
# File 'lib/fluent/plugin/in_glusterfs_log.rb', line 44 def parse_line(line) super begin return nil, nil unless line[0,1] == '[' time = 0 record = {} if @regex =~ line record = { @field[:date] => $1, @field[:time] => $2, @field[:time_usec] => $3, @field[:log_level] => $4, @field[:source_file_name] => $5, @field[:source_line] => $6, @field[:function_name] => $7, @field[:component_name] => $8, @field[:message] => $9, @field[:hostname] => @hostname } time = Time.strptime("#{record[@field[:date]]} #{record[@field[:time]]}", @time_format).to_i elsif @handle_parse_failure now = Time.now.utc datetime = now.to_s.split(' ') record = { @field[:date] => datetime[0], @field[:time] => datetime[1], @field[:log_level] => 'I', @field[:component_name] => 'fluent-plugin-glusterfs', @field[:message] => "Could not parse the line : #{line}", @field[:hostname] => @hostname } time = now.to_i end return time, record rescue => ex raise ex end end |