Search in sources :

Example 11 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.

the class SymRollingFileAppender method appendKey.

protected LoggingEvent appendKey(LoggingEvent event, String key) {
    String message = getMessageWithKey(event, key, ".init");
    LoggingEvent eventClone = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), message, event.getThreadName(), event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(), event.getProperties());
    return eventClone;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 12 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project ats-framework by Axway.

the class DbEventRequestProcessor method insertMessage.

private void insertMessage(LogEventRequest eventRequest, boolean escapeHtml, boolean isRunMessage) throws LoggingException {
    LoggingEvent event = eventRequest.getEvent();
    // appender may try to log before the client has a chance of opening a test case.
    if (eventProcessorState.getLifeCycleState() == LifeCycleState.RUN_STARTED || isRunMessage) {
        if (!ActiveDbAppender.isBeforeAndAfterMessagesLoggingSupported) {
            return;
        }
        int runId = eventProcessorState.getRunId();
        if (isRunMessage && eventProcessorState.getTestCaseState().getRunId() != 0) {
            runId = eventProcessorState.getTestCaseState().getRunId();
        }
        Level level = event.getLevel();
        try {
            dbAccess.insertRunMessage(getLoggingMesage(event), convertMsgLevel(level), escapeHtml, machineName, eventRequest.getThreadName(), eventRequest.getTimestamp(), runId, true);
        } catch (LoggingException e) {
            handleDeletedRun(e, runId);
        }
    } else if (eventProcessorState.getLifeCycleState() == LifeCycleState.TEST_CASE_STARTED) {
        final int testcaseId = eventProcessorState.getTestCaseId();
        if (!deletedTestcases.contains(testcaseId)) {
            Level level = event.getLevel();
            try {
                dbAccess.insertMessage(getLoggingMesage(event), convertMsgLevel(level), escapeHtml, machineName, eventRequest.getThreadName(), eventRequest.getTimestamp(), testcaseId, true);
            } catch (LoggingException e) {
                handleDeletedTestcase(e, testcaseId);
            }
        }
    } else if (eventProcessorState.getLifeCycleState() == LifeCycleState.SUITE_STARTED) {
        if (!ActiveDbAppender.isBeforeAndAfterMessagesLoggingSupported) {
            return;
        }
        final int suiteId = eventProcessorState.getSuiteId();
        Level level = event.getLevel();
        try {
            dbAccess.insertSuiteMessage(getLoggingMesage(event), convertMsgLevel(level), escapeHtml, machineName, eventRequest.getThreadName(), eventRequest.getTimestamp(), suiteId, true);
        } catch (LoggingException e) {
            handleDeletedSuite(e, suiteId);
        }
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) LoggingException(com.axway.ats.log.autodb.exceptions.LoggingException) Level(org.apache.log4j.Level) SystemLogLevel(com.axway.ats.log.model.SystemLogLevel)

Example 13 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project ats-framework by Axway.

the class DbEventRequestProcessor method processEventRequest.

public void processEventRequest(LogEventRequest eventRequest) throws LoggingException {
    if (testcaseToDelete > 0) {
        /* Pause for a moment processing the current event.
             * This is (delete testcase)event is not coming from the FIFO queue, as we want to process it as
             * soon as possible, so any events related to this testcase are directly skipped.
             */
        deleteRequestedTestcase();
    // now resume the processing of the current event that came from the queue
    }
    if (isBatchMode && eventRequest == null) {
        // timeout waiting for next event - flush the current cache
        dbAccess.flushCache();
        return;
    }
    LoggingEvent event = eventRequest.getEvent();
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbAppenderEvent = (AbstractLoggingEvent) event;
        //first check if we can process the event at all
        dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
        if (isBatchMode && !(event instanceof CacheableEvent) && eventProcessorState.getLifeCycleState() == LifeCycleState.TEST_CASE_STARTED) {
            // this event can not be cached - flush the current cache
            dbAccess.flushCache();
        }
        switch(dbAppenderEvent.getEventType()) {
            case START_RUN:
                startRun((StartRunEvent) event, eventRequest.getTimestamp());
                break;
            case END_RUN:
                endRun(eventRequest.getTimestamp());
                break;
            case UPDATE_RUN:
                updateRun((UpdateRunEvent) event);
                break;
            case ADD_RUN_METAINFO:
                addRunMetainfo((AddRunMetainfoEvent) event);
                break;
            case START_SUITE:
                startSuite((StartSuiteEvent) event, eventRequest.getTimestamp());
                break;
            case END_SUITE:
                endSuite(eventRequest.getTimestamp());
                break;
            case CLEAR_SCENARIO_METAINFO:
                clearScenarioMetainfo();
                break;
            case ADD_SCENARIO_METAINFO:
                addScenarioMetainfo((AddScenarioMetainfoEvent) event);
                break;
            case START_TEST_CASE:
                startTestCase((StartTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case END_TEST_CASE:
                endTestCase((EndTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case JOIN_TEST_CASE:
                joinTestCase((JoinTestCaseEvent) event);
                break;
            case LEAVE_TEST_CASE:
                leaveTestCase();
                break;
            case REMEMBER_LOADQUEUE_STATE:
                rememberLoadQueueState((RememberLoadQueueStateEvent) event);
                break;
            case CLEANUP_LOADQUEUE_STATE:
                cleanupLoadQueueState((CleanupLoadQueueStateEvent) event);
                break;
            case END_LOADQUEUE:
                endLoadQueue((EndLoadQueueEvent) event, eventRequest.getTimestamp());
                break;
            case REGISTER_THREAD_WITH_LOADQUEUE:
                registerThreadWithLoadQueue((RegisterThreadWithLoadQueueEvent) event);
                break;
            case START_CHECKPOINT:
                startCheckpoint((StartCheckpointEvent) event);
                break;
            case END_CHECKPOINT:
                endCheckpoint((EndCheckpointEvent) event);
                break;
            case INSERT_CHECKPOINT:
                insertCheckpoint((InsertCheckpointEvent) event);
                break;
            case INSERT_SYSTEM_STAT:
                insertSystemStatistics((InsertSystemStatisticEvent) event);
                break;
            case INSERT_MESSAGE:
                InsertMessageEvent insertMessageEvent = (InsertMessageEvent) event;
                insertMessage(eventRequest, insertMessageEvent.isEscapeHtml(), insertMessageEvent.isRunMessage());
                break;
            default:
                throw new LoggingException("Unsupported logging event of type: " + dbAppenderEvent.getEventType());
        }
    } else {
        insertMessage(eventRequest, false, false);
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) LoggingException(com.axway.ats.log.autodb.exceptions.LoggingException) InsertMessageEvent(com.axway.ats.log.autodb.events.InsertMessageEvent) CacheableEvent(com.axway.ats.log.autodb.model.CacheableEvent)

Example 14 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project carbondata by apache.

the class AuditExtendedRollingFileAppenderTest_UT method testSubAppendLoggingEvent.

@Test
public void testSubAppendLoggingEvent() {
    Logger logger = Logger.getLogger(this.getClass());
    LoggingEvent event = new LoggingEvent(null, logger, 0L, AuditLevel.AUDIT, null, null);
    Deencapsulation.setField(rAppender, "qw", null);
    try {
        rAppender.subAppend(event);
    } catch (Exception e) {
    //
    }
    Assert.assertTrue(true);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 15 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project cloudstack by apache.

the class AlertsSyslogAppender method append.

@Override
protected void append(LoggingEvent event) {
    if (!isAsSevereAsThreshold(event.getLevel())) {
        return;
    }
    if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) {
        try {
            String logMessage = event.getRenderedMessage();
            if (logMessage.contains("alertType") && logMessage.contains("message")) {
                parseMessage(logMessage);
                String syslogMessage = createSyslogMessage();
                LoggingEvent syslogEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getLevel(), syslogMessage, null);
                for (SyslogAppender syslogAppender : _syslogAppenders) {
                    syslogAppender.append(syslogEvent);
                }
            }
        } catch (Exception e) {
            errorHandler.error(e.getMessage());
        }
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) SyslogAppender(org.apache.log4j.net.SyslogAppender) UnknownHostException(java.net.UnknownHostException)

Aggregations

LoggingEvent (org.apache.log4j.spi.LoggingEvent)48 Test (org.junit.Test)21 Logger (org.apache.log4j.Logger)12 Pattern (java.util.regex.Pattern)7 Matcher (java.util.regex.Matcher)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)3 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)2 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)2 IOException (java.io.IOException)2 Appender (org.apache.log4j.Appender)2 Category (org.apache.log4j.Category)2 Level (org.apache.log4j.Level)2 Filter (org.apache.log4j.spi.Filter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 SystemLogLevel (com.axway.ats.log.model.SystemLogLevel)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1