SLF4JLog extends AbstractLog { protected void log(org.slf4j.Logger log, String text) { if (log.isInfoEnabled()) { final String message = logPrefix != null ? (logPrefix + text) : text; if (log instanceof LocationAwareLogger) { final LocationAwareLogger la = (LocationAwareLogger) log; la.log(null, callerFQCN, LocationAwareLogger.INFO_INT, message, null, null); } else { log.info(message); } } } SLF4JLog(SessionID sessionID, String eventCategory, String errorEventCategory,
            String incomingMsgCategory, String outgoingMsgCategory, boolean prependSessionID,
            boolean logHeartbeats, String inCallerFQCN); void onEvent(String text); void onErrorEvent(String text); void clear(); static final String DEFAULT_EVENT_CATEGORY; static final String DEFAULT_ERROR_EVENT_CATEGORY; static final String DEFAULT_INCOMING_MSG_CATEGORY; static final String DEFAULT_OUTGOING_MSG_CATEGORY; }
@Test public void testLog() throws Exception { final SessionID sessionID = new SessionID("FIX.4.2", "SENDER" + System.currentTimeMillis(), "TARGET" + System.currentTimeMillis()); final long systemTime = SystemTime.currentTimeMillis(); SystemTime.setTimeSource(new MockSystemTimeSource(systemTime)); final SessionSettings settings = new SessionSettings(); final SLF4JLogFactory factory = new SLF4JLogFactory(settings); Log log = factory.create(sessionID); final String loggedText = "TEST123"; setUpLoggerForTest(SLF4JLog.DEFAULT_EVENT_CATEGORY); log.onEvent(loggedText); assertMessageLogged(SLF4JLog.DEFAULT_EVENT_CATEGORY, sessionID, loggedText); setUpLoggerForTest(SLF4JLog.DEFAULT_ERROR_EVENT_CATEGORY); log.onErrorEvent(loggedText); assertMessageLogged(SLF4JLog.DEFAULT_ERROR_EVENT_CATEGORY, sessionID, loggedText); setUpLoggerForTest(SLF4JLog.DEFAULT_INCOMING_MSG_CATEGORY); log.onIncoming(loggedText); assertMessageLogged(SLF4JLog.DEFAULT_INCOMING_MSG_CATEGORY, sessionID, loggedText); setUpLoggerForTest(SLF4JLog.DEFAULT_OUTGOING_MSG_CATEGORY); log.onOutgoing(loggedText); assertMessageLogged(SLF4JLog.DEFAULT_OUTGOING_MSG_CATEGORY, sessionID, loggedText); settings.setString(sessionID, SLF4JLogFactory.SETTING_EVENT_CATEGORY, "event"); settings.setString(sessionID, SLF4JLogFactory.SETTING_ERROR_EVENT_CATEGORY, "errorEvent"); settings.setString(sessionID, SLF4JLogFactory.SETTING_INMSG_CATEGORY, "in"); settings.setString(sessionID, SLF4JLogFactory.SETTING_OUTMSG_CATEGORY, "out"); log = factory.create(sessionID); setUpLoggerForTest("event"); log.onEvent(loggedText); assertMessageLogged("event", sessionID, loggedText); setUpLoggerForTest("errorEvent"); log.onErrorEvent(loggedText); assertMessageLogged("errorEvent", sessionID, loggedText); setUpLoggerForTest("in"); log.onIncoming(loggedText); assertMessageLogged("in", sessionID, loggedText); setUpLoggerForTest("out"); log.onOutgoing(loggedText); assertMessageLogged("out", sessionID, loggedText); }