1   package org.slf4j.ext;
2   
3   import org.slf4j.LoggerFactory;
4   import org.slf4j.Marker;
5   import org.slf4j.MarkerFactory;
6   import org.slf4j.spi.LocationAwareLogger;
7   
8   /**
9    * Simple Logger used to log events. All events are directed to a logger named "EventLogger"
10   * with a level of INFO and with an Event marker.
11   *
12   * @author Ralph Goers
13   */
14  public class EventLogger {
15  
16    private static final String FQCN = EventLogger.class.getName();
17  
18    static Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
19  
20    private static LoggerWrapper eventLogger =
21        new LoggerWrapper(LoggerFactory.getLogger("EventLogger"), FQCN);
22  
23    /**
24     * There can only be a single EventLogger.
25     */
26    private EventLogger() {
27    }
28  
29    /**
30     * Logs the event.
31     *
32     * @param data The EventData.
33     */
34    public static void logEvent(EventData data) {
35      if (eventLogger.instanceofLAL) {
36        ((LocationAwareLogger) eventLogger.logger).log(EVENT_MARKER, FQCN,
37            LocationAwareLogger.INFO_INT, data.toXML(), null);
38      } else {
39        eventLogger.logger.info(EVENT_MARKER, data.toXML(), data);
40      }
41    }
42  }