Class: LogStash::Modules::FileReader

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/modules/file_reader.rb

Class Method Summary collapse

Class Method Details

.glob(path) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/logstash/modules/file_reader.rb', line 27

def self.glob(path)
  files = Dir.glob(path)
  if files.empty?
    logger.warn("No files found for glob", :pattern => path)
  end
  files
end

.read(path) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/logstash/modules/file_reader.rb', line 8

def self.read(path)
  begin
    ::File.read(path)
  rescue => e
    logger.error("Error when reading file from path", :path => path)
    ""
  end
end

.read_json(path) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/logstash/modules/file_reader.rb', line 17

def self.read_json(path)
  json = read(path)
  begin
    LogStash::Json.load(json)
  rescue => e
    logger.error("Error when parsing json from path", :path => path)
    return {}
  end
end