I am trying to use this solution to fetch the process id and print it out in the log
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
String pid = rt.getName();
ThreadContext.put("PID", pid);
Edit : In my logger class I can see we are importing. so I can infer that we are definitely using SL4J facade with most likely log4j2.x as per dependency tree.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
I could see form the dubugger that the code is correctly fetching the process ID, but the log simple isnt showing it and there is no other errors. My log currently looks like this
2023-05-22 10:36:54,487 [] DEBUG beanutils.converters.ArrayConverter - Setting default value: [Ljava.lang.Short;@7a3a49e5
It is not able to fetch the PID still.This is what I have in my log4j config.
log4j.appender.consoleAppender.layout.ConversionPattern=%d [%X{PID}] %-5p %c{3} %x - %m%n
My dependency tree looks like this. May be Sl4J is interfering?
λ mvn dependency:tree |grep log4
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.17.2:compile
[INFO] | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.17.2:provided
[INFO] | +- org.apache.logging.log4j:log4j-1.2-api:jar:2.17.2:provided
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.17.2:compile
Any ideas as to what i might be doing wrong or what can i do to debug this further? I tried using log4j2.x config. But it completely stopped logging and gave this warning
log4j:WARN Please initialize the log4j system properly.