Skip to content
Advertisement

Get PID in logback log file

When using logback outside of Spring-Boot, how can I get the ProcessID into the log file name?

In the RollingFileAppender I’d like to define:

JavaScript

How can I get the ${PID} set or is there a standard way of obtaining this?

Advertisement

Answer

  1. Learn how to get the own PID from inside the JVM – How can a Java program get its own process ID?
    JavaScript
  2. Create a custom PropertyDefiner:
    JavaScript
  3. Use that property definer to inject a property into the logback:
    JavaScript

… or use the logback.groovy instead of logback.xml, there you can just access every bit of JVM directly.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement