Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2428

Use the AuditExceptionHandler for validation exceptions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Log4j-Audit 1.0.0
    • Log4j-Audit 1.0.1
    • Log4j-Audit
    • None

    Description

      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:

      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();
      }
      

      And I want to get rid of the try/catch blocks that are now needed because the setters can trigger exceptions too.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              shadow Andrei Ivanov
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: