Skip to content

Commit 34f8306

Browse files
committed
update path.log to path.logs directory, and respect it in log4j2
Fixes #5876
1 parent 5472186 commit 34f8306

File tree

9 files changed

+29
-36
lines changed

9 files changed

+29
-36
lines changed

config/log4j2.properties

+14-25
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,26 @@ status = error
22
name = LogstashPropertiesConfig
33

44
appender.console.type = Console
5-
appender.console.name = STDOUT
6-
7-
# Pattern Logging
8-
#
5+
appender.console.name = console
96
appender.console.layout.type = PatternLayout
107
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %m%n
11-
128
# JSON Logging
13-
#
149
# appender.console.layout.type = JSONLayout
1510
# appender.console.layout.compact = true
1611
# appender.console.layout.eventEol = true
1712

18-
# Rolling File Appender
19-
#
20-
#property.filename = /tmp/logstash/logstash.log
21-
#
22-
# appender.rolling.type = RollingFile
23-
# appender.rolling.name = RollingFile
24-
# appender.rolling.fileName = ${filename}
25-
# appender.rolling.filePattern = /tmp/logstash/logstash-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
26-
# appender.rolling.policies.type = Policies
27-
# appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
28-
# appender.rolling.policies.time.interval = 2
29-
# appender.rolling.policies.time.modulate = true
30-
# appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
31-
# appender.rolling.policies.size.size=100MB
32-
# appender.rolling.strategy.type = DefaultRolloverStrategy
33-
# appender.rolling.strategy.max = 5
34-
# appender.rolling.layout.type = PatternLayout
35-
# appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %m%n
13+
appender.rolling.type = RollingFile
14+
appender.rolling.name = rolling
15+
appender.rolling.fileName = ${sys:ls.logs}/logstash.log
16+
appender.rolling.layout.type = PatternLayout
17+
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %.10000m%n
18+
appender.rolling.filePattern = ${sys:ls.logs}/logstash-%d{yyyy-MM-dd}.log
19+
appender.rolling.policies.type = Policies
20+
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
21+
appender.rolling.policies.time.interval = 1
22+
appender.rolling.policies.time.modulate = true
3623

3724
rootLogger.level = error
38-
rootLogger.appenderRef.stdout.ref = STDOUT
25+
rootLogger.appenderRef.console.ref = console
26+
rootLogger.appenderRef.rolling.ref = rolling
27+

config/logstash.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
# * trace
108108
#
109109
# log.level: warn
110-
# path.log:
110+
# path.logs: LOGSTASH_HOME/logs
111111
#
112112
# ------------ Other Settings --------------
113113
#

docs/static/command-line-flags.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ added[5.0.0-alpha3, Command-line flags have dots instead of dashes in their name
6565
`PATH/logstash/TYPE/NAME.rb` where `TYPE` is `inputs`, `filters`, `outputs`, or `codecs`,
6666
and `NAME` is the name of the plugin.
6767

68-
*`-l, --path.log FILE`*::
69-
Write Logstash internal logs to the given file. Without this flag, Logstash will emit logs to standard output.
68+
*`-l, --path.logs PATH`*::
69+
Directory to Write Logstash internal logs to.
7070

7171
*`--log.level LEVEL`*::
7272
Set the log level for Logstash. Possible values are:

logstash-core/lib/logstash/environment.rb

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module Environment
3636
Setting::String.new("log.level", "warn", true, ["fatal", "error", "warn", "debug", "info", "trace"]),
3737
Setting::Boolean.new("version", false),
3838
Setting::Boolean.new("help", false),
39-
Setting::String.new("path.log", nil, false),
4039
Setting::String.new("log.format", "plain", true, ["json", "plain"]),
4140
Setting::String.new("http.host", "127.0.0.1"),
4241
Setting::PortRange.new("http.port", 9600..9700),

logstash-core/lib/logstash/runner.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
class LogStash::Runner < Clamp::StrictCommand
2121
include LogStash::Util::Loggable
22-
# The `path.settings` need to be defined in the runner instead of the `logstash-core/lib/logstash/environment.rb`
22+
# The `path.settings` and `path.logs` need to be defined in the runner instead of the `logstash-core/lib/logstash/environment.rb`
2323
# because the `Environment::LOGSTASH_HOME` doesn't exist in the context of the `logstash-core` gem.
2424
#
2525
# See issue https://github.com/elastic/logstash/issues/5361
2626
LogStash::SETTINGS.register(LogStash::Setting::String.new("path.settings", ::File.join(LogStash::Environment::LOGSTASH_HOME, "config")))
27+
LogStash::SETTINGS.register(LogStash::Setting::String.new("path.logs", ::File.join(LogStash::Environment::LOGSTASH_HOME, "logs")))
2728

2829
# Node Settings
2930
option ["-n", "--node.name"], "NAME",
@@ -77,9 +78,10 @@ class LogStash::Runner < Clamp::StrictCommand
7778
:default => LogStash::SETTINGS.get_default("path.plugins")
7879

7980
# Logging Settings
80-
option ["-l", "--path.log"], "FILE",
81+
option ["-l", "--path.logs"], "PATH",
8182
I18n.t("logstash.runner.flag.log"),
82-
:attribute_name => "path.log"
83+
:attribute_name => "path.logs",
84+
:default => LogStash::SETTINGS.get_default("path.logs")
8385

8486
option "--log.level", "LEVEL", I18n.t("logstash.runner.flag.log_level"),
8587
:default => LogStash::SETTINGS.get_default("log.level"),
@@ -172,8 +174,9 @@ def run(args)
172174
# Configure Logstash logging facility, this need to be done before everything else to
173175
# make sure the logger has the correct settings and the log level is correctly defined.
174176
# TODO(talevy): cleanly support `path.logs` setting in log4j
177+
java.lang.System.setProperty("ls.logs", setting("path.logs"))
175178
unless java.lang.System.getProperty("log4j.configurationFile")
176-
log4j_config_location = setting("path.settings") + "/log4j2.properties"
179+
log4j_config_location = ::File.join(setting("path.settings"), "log4j2.properties")
177180
LogStash::Logging::Logger::initialize(log4j_config_location)
178181
end
179182

logstash-core/locales/en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ en:
194194
path_settings: |+
195195
Directory containing logstash.yml file. This can also be
196196
set through the LS_SETTINGS_DIR environment variable.
197+
path_logs: |+
198+
Directory to Write Logstash internal logs to.
197199
auto_reload: |+
198200
Monitor configuration changes and reload
199201
whenever it is changed.

pkg/centos/after-install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ chown logstash:logstash /var/lib/logstash
44
chmod 0644 /etc/logrotate.d/logstash
55
sed -i \
66
-e 's|# path.config:|path.config: /etc/logstash/conf.d|' \
7-
-e 's|# path.log:|path.log: /var/log/logstash/logstash.log|' \
7+
-e 's|# path.logs:|path.logs: /var/log/logstash|' \
88
-e 's|# path.data:|path.data: /var/lib/logstash|' \
99
/etc/logstash/logstash.yml
1010
/usr/share/logstash/bin/system-install /etc/logstash/startup.options

pkg/debian/after-install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ chmod 755 /etc/logstash
77
chmod 0644 /etc/logrotate.d/logstash
88
sed -i \
99
-e 's|# path.config:|path.config: /etc/logstash/conf.d|' \
10-
-e 's|# path.log:|path.log: /var/log/logstash/logstash.log|' \
10+
-e 's|# path.logs:|path.logs: /var/log/logstash|' \
1111
-e 's|# path.data:|path.data: /var/lib/logstash|' \
1212
/etc/logstash/logstash.yml
1313
/usr/share/logstash/bin/system-install /etc/logstash/startup.options

pkg/ubuntu/after-install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ chown logstash:logstash /var/lib/logstash
66
chmod 0644 /etc/logrotate.d/logstash
77
sed -i \
88
-e 's|# path.config:|path.config: /etc/logstash/conf.d|' \
9-
-e 's|# path.log:|path.log: /var/log/logstash/logstash.log|' \
9+
-e 's|# path.logs:|path.logs: /var/log/logstash|' \
1010
-e 's|# path.data:|path.data: /var/lib/logstash|' \
1111
/etc/logstash/logstash.yml
1212
/usr/share/logstash/bin/system-install /etc/logstash/startup.options

0 commit comments

Comments
 (0)