0

I would like to print some MDC values in Glassfish, but I can't find where to change the logging pattern.

This is what I have in my code:

MDC.put("something", "SOME_VALUE");

But then I need to configure somewhere the pattern like this:

%-4r [%thread] %-5level %X{something} - %msg%n

So my simple question is: where should I put that in Glassfish?

I am using:

  • Glassfish 4.1
  • slf4j
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • Hi @Pablo, did you get this working? I am working on an application that uses `com.sun.enterprise.server.logging.UniformLogFormatter`. I am trying to make use of MDC to log some custom headers.Can change to SimpleFormatter, but checking if we can make this work with exiting Formatter. Thanks – Priyak Dey Apr 11 '23 at 07:01

1 Answers1

1

You can configure the logging output in <glassfish-install-dir>/glassfish/domains/domain1/config/logging.properties file.

To format your output you can use the java.util.logging.SimpleFormatter.

Your logging.properties might look like this

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%-4r [%thread] %-5level %X{something} - %msg%n
Tobi Tiggers
  • 442
  • 3
  • 14