elasticsearch/docs/reference/setup/important-settings/gc-logging.asciidoc
Daniel Mitterdorfer 8fc2d6af4c
Add log level for JVM logs (#92382)
With this commit we specify `level` in JVM logs. `level` helps to filter
more severe messages from mere debugging messages in logs and with this
change we are able to use it also for JVM logs.

Here are a few example lines:

Before:

```
[2022-12-15T06:19:16.936+0000][15181][gc,start    ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)
```

After:

```
[2022-12-15T06:22:27.932+0000][16320][info][gc,start    ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)
[2022-12-15T06:22:27.932+0000][16320][debug][gc,age      ] GC(0) Desired survivor size 14680064 bytes, new threshold 15 (max threshold 15)
[2022-12-15T06:22:27.935+0000][16320][info ][gc,phases   ] GC(0)   Pre Evacuate Collection Set: 0.1ms
[2022-12-15T06:22:27.935+0000][16320][trace][gc,age      ] GC(0) Age table with threshold 15 (max threshold 15)
```

Notice, that the log level might have trailing spaces.

See also
https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#xlog-tags-and-levels
for the available log levels.
2023-01-10 07:58:18 +01:00

52 lines
2 KiB
Text

[[gc-logging]]
[discrete]
==== GC logging settings
By default, {es} enables garbage collection (GC) logs. These are configured in
<<set-jvm-options,`jvm.options`>> and output to the same default location as
the {es} logs. The default configuration rotates the logs every 64 MB and
can consume up to 2 GB of disk space.
You can reconfigure JVM logging using the command line options described in
https://openjdk.java.net/jeps/158[JEP 158: Unified JVM Logging]. Unless you
change the default `jvm.options` file directly, the {es} default
configuration is applied in addition to your own settings. To disable the
default configuration, first disable logging by supplying the
`-Xlog:disable` option, then supply your own command line options. This
disables __all__ JVM logging, so be sure to review the available options
and enable everything that you require.
To see further options not contained in the original JEP, see
https://docs.oracle.com/en/java/javase/13/docs/specs/man/java.html#enable-logging-with-the-jvm-unified-logging-framework[Enable
Logging with the JVM Unified Logging Framework].
[[gc-logging-examples]]
[discrete]
==== Examples
Change the default GC log output location to `/opt/my-app/gc.log` by
creating `$ES_HOME/config/jvm.options.d/gc.options` with some sample
options:
[source,shell]
----
# Turn off all previous logging configuratons
-Xlog:disable
# Default settings from JEP 158, but with `utctime` instead of `uptime` to match the next line
-Xlog:all=warning:stderr:utctime,level,tags
# Enable GC logging to a custom location with a variety of options
-Xlog:gc*,gc+age=trace,safepoint:file=/opt/my-app/gc.log:utctime,level,pid,tags:filecount=32,filesize=64m
----
Configure an {es} <<docker,Docker container>> to send GC debug logs to
standard error (`stderr`). This lets the container orchestrator
handle the output. If using the `ES_JAVA_OPTS` environment variable,
specify:
[source,sh]
----
MY_OPTS="-Xlog:disable -Xlog:all=warning:stderr:utctime,level,tags -Xlog:gc=debug:stderr:utctime"
docker run -e ES_JAVA_OPTS="$MY_OPTS" # etc
----