Andrei Ivanov created LOG4J2-2428:
-------------------------------------

             Summary: Use the {{AuditExceptionHandler}} for validation 
exceptions
                 Key: LOG4J2-2428
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2428
             Project: Log4j 2
          Issue Type: Improvement
          Components: Log4j-Audit
    Affects Versions: Log4j-Audit 1.0.0
            Reporter: Andrei Ivanov


Since I don't want the audit exceptions to stop the execution of the 
application code, I've tried defining a simple {{AuditExceptionHandler}} that 
just logs the exceptions.

The {{AuditExceptionHandler}} is invoked currently only to handle exceptions 
caused by the {{logEvent}} method, but it would be nice to use it for the 
validation exceptions as well.

Otherwise my logging code looks like this:
{code:java}
try {
        logCashPaymentOut(result);
} catch (Exception e) {
        // log exception here
}

 private void logCashPaymentOut(SalesTransaction salesTransaction) {
         CashPaymentOut event = LogEventFactory.getEvent(CashPaymentOut.class);
        event.setSalesTransaction(salesTransaction.getUuid());
        event.setAmount(salesTransaction.getReturn().getAmount());
        event.setCurrency(salesTransaction.getReturn().getCurrency().name());
        event.setCurrency("Cash return");
        event.logEvent();
}
{code}
And I want to get rid of the try/catch blocks that are now needed because the 
setters can trigger exceptions too.


P.S. I've discovered that even though {{LogEventFactory}} has a 
{{defaultExceptionHandler}} property, it doesn't set it on the events it 
creates through {{getEvent}}, so I've created my own implementation of 
{{LogEventFactory}}.
Can this be changed?

P.S. 2 Should the signature of {{LogEventFactory.getEvent}} be changed like 
this?
{code:java}
public static <T extends AuditEvent> T getEvent(Class<T> intrface)
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to