[logback-user] How to output short exception when Marker is present, but full otherwise?

te at spudsoft.co.uk te at spudsoft.co.uk
Wed Oct 23 09:13:44 CEST 2019


Hi,

I want this:

     logger.debug("Test logging: ", new IllegalStateException("Wibble"));

to give me a full stack trace, and this:

     logger.debug(MarkerFactory.getMarker("MINIMAL_EXCEPTION"), "Test 
logging: ", new IllegalStateException("Wibble"));

to just output the class and message.

I don't have Janino, and I'm trying to keep it all as small as possible 
(also not sure I could pay the price of expression evaluation for each 
message).

The closest I've got is this:

   <evaluator name="DISPLAY_EX_EVAL" 
class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
     <marker>MINIMAL_EXCEPTION</marker>
   </evaluator>

   <appender name="STDOUTPUT" class="ch.qos.logback.core.ConsoleAppender">
     <encoder>
       <charset>UTF-8</charset>
       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %line - 
%msg%ex{full, DISPLAY_EX_EVAL}%n</pattern>
     </encoder>
   </appender>
   <contextListener 
class="ch.qos.logback.classic.jul.LevelChangePropagator" />

But that doesn't output exception at all when the Marker is present.

Is there any way to get what I want without a more complex expression?

Thanks.

Jim



More information about the logback-user mailing list