Class: LogStash::Config::Source::Local::ConfigPathLoader
- Inherits:
-
Object
- Object
- LogStash::Config::Source::Local::ConfigPathLoader
show all
- Includes:
- Util::Loggable
- Defined in:
- lib/logstash/config/source/local.rb
Constant Summary
collapse
- TEMPORARY_FILE_RE =
/~$/
- LOCAL_FILE_URI =
/^file:\/\//i
Class Method Summary
collapse
Instance Method Summary
collapse
included, #logger, #slow_logger
Constructor Details
51
52
53
|
# File 'lib/logstash/config/source/local.rb', line 51
def initialize(path)
@path = normalize_path(path)
end
|
Class Method Details
.read(path) ⇒ Object
95
96
97
|
# File 'lib/logstash/config/source/local.rb', line 95
def self.read(path)
ConfigPathLoader.new(path).read
end
|
Instance Method Details
#read ⇒ 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
|
# File 'lib/logstash/config/source/local.rb', line 55
def read
config_parts = []
encoding_issue_files = []
if logger.debug?
logger.debug("Skipping the following files while reading config since they don't match the specified glob pattern", :files => get_unmatched_files)
end
get_matched_files.each do |file|
next unless ::File.file?(file)
logger.debug("Reading config file", :config_file => file)
if temporary_file?(file)
logger.warn("NOT reading config file because it is a temp file", :config_file => file)
next
end
config_string = ::File.read(file)
config_string.force_encoding("UTF-8")
if config_string.valid_encoding?
part = org.logstash.common.SourceWithMetadata.new("file", file, 0, 0, config_string)
config_parts << part
else
encoding_issue_files << file
end
end
if encoding_issue_files.any?
raise LogStash::ConfigLoadingError, "The following config files contains non-ascii characters but are not UTF-8 encoded #{encoding_issue_files}"
end
if config_parts.empty?
logger.info("No config files found in path", :path => path)
end
config_parts
end
|