logging: move init into environment's settings post-processor (#13221) (#13663)

* logging: move init into environment's settings post-processor

Ensures that the non-runner command line utilities like `bin/logstash-keystore`
correctly initialize the logger as-configured.

* fixup: ensure we get ruby stdlib URI & File

(cherry picked from commit 2a5e54cd21)
This commit is contained in:
Ry Biesemeyer 2022-01-24 08:53:09 -08:00 committed by GitHub
parent 8d057881ae
commit 319e67dceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 16 deletions

View file

@ -112,6 +112,23 @@ module LogStash
default_dlq_file_path = ::File.join(SETTINGS.get("path.data"), "dead_letter_queue") default_dlq_file_path = ::File.join(SETTINGS.get("path.data"), "dead_letter_queue")
SETTINGS.register Setting::WritableDirectory.new("path.dead_letter_queue", default_dlq_file_path) SETTINGS.register Setting::WritableDirectory.new("path.dead_letter_queue", default_dlq_file_path)
SETTINGS.on_post_process do |settings|
# Configure Logstash logging facility. This needs to be done as early as possible to
# make sure the logger has the correct settings tnd the log level is correctly defined.
java.lang.System.setProperty("ls.logs", settings.get("path.logs"))
java.lang.System.setProperty("ls.log.format", settings.get("log.format"))
java.lang.System.setProperty("ls.log.level", settings.get("log.level"))
java.lang.System.setProperty("ls.pipeline.separate_logs", settings.get("pipeline.separate_logs").to_s)
unless java.lang.System.getProperty("log4j.configurationFile")
log4j_config_location = ::File.join(settings.get("path.settings"), "log4j2.properties")
# Windows safe way to produce a file: URI.
file_schema = "file://" + (LogStash::Environment.windows? ? "/" : "")
LogStash::Logging::Logger::reconfigure(::URI.encode(file_schema + ::File.absolute_path(log4j_config_location)))
end
# override log level that may have been introduced from a custom log4j config file
LogStash::Logging::Logger::configure_logging(settings.get("log.level"))
end
SETTINGS.on_post_process do |settings| SETTINGS.on_post_process do |settings|
# If the data path is overridden but the queue path isn't recompute the queue path # If the data path is overridden but the queue path isn't recompute the queue path

View file

@ -299,22 +299,6 @@ class LogStash::Runner < Clamp::StrictCommand
require "logstash/util/java_version" require "logstash/util/java_version"
require "stud/task" require "stud/task"
# Configure Logstash logging facility, this need to be done before everything else to
# make sure the logger has the correct settings and the log level is correctly defined.
java.lang.System.setProperty("ls.logs", setting("path.logs"))
java.lang.System.setProperty("ls.log.format", setting("log.format"))
java.lang.System.setProperty("ls.log.level", setting("log.level"))
java.lang.System.setProperty("ls.pipeline.separate_logs", setting("pipeline.separate_logs").to_s)
unless java.lang.System.getProperty("log4j.configurationFile")
log4j_config_location = ::File.join(setting("path.settings"), "log4j2.properties")
# Windows safe way to produce a file: URI.
file_schema = "file://" + (LogStash::Environment.windows? ? "/" : "")
LogStash::Logging::Logger::reconfigure(URI.encode(file_schema + File.absolute_path(log4j_config_location)))
end
# override log level that may have been introduced from a custom log4j config file
LogStash::Logging::Logger::configure_logging(setting("log.level"))
if log_configuration_contains_javascript_usage? if log_configuration_contains_javascript_usage?
logger.warn("Logging configuration uses appender or filter with scripting language JavaScript, which will be removed in a future major release of Logstash.") logger.warn("Logging configuration uses appender or filter with scripting language JavaScript, which will be removed in a future major release of Logstash.")
end end