Skip to content

Commit 3950c3a

Browse files
authored
Document how to change GC logging behaviour (#52879)
Closes #43990. Describe how to change the default GC settings without changing the default `jvm.options`. Give examples using `jvm.options.d`, and `ES_JAVA_OPTS` with Docker.
1 parent d32b667 commit 3950c3a

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11
[[gc-logging]]
22
=== GC logging
33

4-
By default, Elasticsearch enables GC logs. These are configured in
5-
<<jvm-options,`jvm.options`>> and default to the same default location as the
6-
Elasticsearch logs. The default configuration rotates the logs every 64 MB and
4+
By default, {es} enables GC logs. These are configured in
5+
<<jvm-options,`jvm.options`>> and output to the same default location as
6+
the {es} logs. The default configuration rotates the logs every 64 MB and
77
can consume up to 2 GB of disk space.
8+
9+
You can reconfigure JVM logging using the command line options described in
10+
https://openjdk.java.net/jeps/158[JEP 158: Unified JVM Logging]. Unless you
11+
change the default `jvm.options` file directly, the {es} default
12+
configuration is applied in addition to your own settings. To disable the
13+
default configuration, first disable logging by supplying the
14+
`-Xlog:disable` option, then supply your own command line options. This
15+
disables __all__ JVM logging, so be sure to review the available options
16+
and enable everything that you require.
17+
18+
To see further options not contained in the original JEP, see
19+
https://docs.oracle.com/en/java/javase/13/docs/specs/man/java.html#enable-logging-with-the-jvm-unified-logging-framework[Enable
20+
Logging with the JVM Unified Logging Framework].
21+
22+
==== Examples
23+
24+
* Change the default GC log output location to `/opt/my-app/gc.log` by
25+
creating `$ES_HOME/config/jvm.options.d/gc.options` with some sample
26+
options:
27+
+
28+
[source,shell]
29+
--------------------------------------------
30+
# Turn off all previous logging configuratons
31+
-Xlog:disable
32+
33+
# Default settings from JEP 158, but with `utctime` instead of `uptime` to match the next line
34+
-Xlog:all=warning:stderr:utctime,level,tags
35+
36+
# Enable GC logging to a custom location with a variety of options
37+
-Xlog:gc*,gc+age=trace,safepoint:file=/opt/my-app/gc.log:utctime,pid,tags:filecount=32,filesize=64m
38+
--------------------------------------------
39+
40+
* Configure an {es} <<docker,Docker container>> to send GC debug logs to
41+
standard error (`stderr`). This lets the container orchestrator
42+
handle the output. If using the `ES_JAVA_OPTS` environment variable,
43+
specify:
44+
+
45+
[source,sh]
46+
--------------------------------------------
47+
MY_OPTS="-Xlog:disable -Xlog:all=warning:stderr:utctime,level,tags -Xlog:gc=debug:stderr:utctime"
48+
docker run -e ES_JAVA_OPTS="$MY_OPTS" # etc
49+
--------------------------------------------

docs/reference/setup/jvm-options.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
You should rarely need to change Java Virtual Machine (JVM) options. If you do,
55
the most likely change is setting the <<heap-size,heap size>>. The remainder of
6-
this document explains in detail how to set JVM options.
6+
this document explains in detail how to set JVM options. You can set options
7+
either with `jvm.options` files or with the `ES_JAVA_OPTS` environment variable.
78

89
The preferred method of setting or overriding JVM options is via JVM options
910
files. When installing from the tar or zip distributions, the root `jvm.options`

0 commit comments

Comments
 (0)