Log4jAuditor implements Auditor { @SuppressWarnings("unchecked") public void audit(AuditEvent event) { initFromMDC(event); LoggingEvent loggingEvent = new LoggingEvent(log.getName(), log, Level.DEBUG, event.getAction(), null); loggingEvent.setProperty("username", event.getUsername()); loggingEvent.setProperty("session", event.getSession()); loggingEvent.setProperty("ip", event.getIp()); Enumeration<Appender> en = log.getAllAppenders(); while (en.hasMoreElements()) { en.nextElement().doAppend(loggingEvent); } } Log4jAuditor();  Log4jAuditor(String loggerName); @SuppressWarnings("unchecked") void audit(AuditEvent event);  }
@Test public void logEvent() { auditor.audit(new AuditEvent("Login").setUsername("decebal1").setSession(getUUID()).setIp("localhost")); }
@Test public void logEventMDC() { MDC.put("username", "decebal2"); MDC.put("session", getUUID()); MDC.put("ip", "127.0.0.1"); auditor.audit(new AuditEvent("Login")); }