My application is using structured json logging and log4j. My goal is to add a new field to json log if a specific throwable is passed into log method as an argument
With mdc this is easy
} catch (SpecificException ex)
MDC.put(key, ex.getData())
logger.error("something bad happened", ex)
MDC.remove(key)
} catch (OtherException ex) {
logger.error("something bad happened", ex)
}
However I would prefer to find a solution that would work project wide possibly without mdc api optimally on a level of log appender. Is anything like this possible to achieve with log4j?