Registration of GC information in the application

Is there a way to redirect garbage collection information (for example, the output of -XX:+PrintGCDetails or -verbose:gc ) to a log in a Java application (sl4j + logback in my case)?

+6
source share
2 answers

These messages are generated by the native JVM process, not Java code, so you can

+5
source

An interesting approach would be to redirect gc.log to the named pipe -Xloggc:/my/named/pipe How to write the GC log to the named pipe

then read the pipe forms the application itself: How to open a Windows named pipe with Java?

and write to an arbitrary (for example, asynchronous) error log from the code.

Tried this on a windows machine. Unfortunately, it is harder to configure on Windows than on Linux.

On Windows, it works mainly with an optional Powershell script (there may also be a dedicated application). This sample project also contains a demo application that you can use immediately to check if GC logs are redirected to Logback through SLF4J.

+3
source

Source: https://habr.com/ru/post/912925/


All Articles