Make node.name available for logging
- Dominant language
- Java
- Stars
- 14.9k
- Forks
- 3.5k
- Avg merge
- 19h 14m
- Merged PRs (30d)
- 63
Description
My setup consists of two Logstash instances, one for receiving events from external sources and another one for actual indexing/filtering. The instances are connected by a Redis server.
It would be cool if we could use the `node.name` setting in `log4j2.properties` and so add the node name to the log message.
Currently, I set up logging to write to `stdout` and then redirecting the output into different files. But if log4j2 would know about the `node.name` I could use the same `log4j2.properties` config for both instances with different files (or even with the same log file for JSON logging).
I'm not sure (untested) but maybe something like the following would be enough:
```diff
diff --git a/logstash-core/lib/logstash/runner.rb b/logstash-core/lib/logstash/runner.rb
index eeed1eb..1529689 100644
--- a/logstash-core/lib/logstash/runner.rb
+++ b/logstash-core/lib/logstash/runner.rb
@@ -188,6 +188,7 @@ class LogStash::Runner < Clamp::StrictCommand
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.node.name", setting("node.name"))
unless java.lang.System.getProperty("log4j.configurationFile")
log4j_config_location = ::File.join(setting("path.settings"), "log4j2.properties")
LogStash::Logging::Logger::initialize("file://" + log4j_config_location)
```
Logstash: 5.0.2
Contributor guide
Assessment
This issue has not been assessed yet.