Search in sources :

Example 1 with Log4JTaskLogs

use of org.ow2.proactive.scheduler.common.task.Log4JTaskLogs in project scheduling by ow2-proactive.

the class EnabledListenJobLogsSupport method flushTaskLogs.

private void flushTaskLogs(TaskResult tr, Appender a, JobId jobId) {
    // if taskResult is not awaited, task is terminated
    TaskLogs logs = tr.getOutput();
    if (logs instanceof Log4JTaskLogs) {
        for (LoggingEvent le : ((Log4JTaskLogs) logs).getAllEvents()) {
            // write into socket appender directly to avoid double lines on other listeners
            a.doAppend(le);
        }
    } else {
        a.doAppend(createLoggingEvent(jobId, logs.getStdoutLogs(false), Level.INFO));
        a.doAppend(createLoggingEvent(jobId, logs.getStderrLogs(false), Level.DEBUG));
    }
}
Also used : TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs)

Example 2 with Log4JTaskLogs

use of org.ow2.proactive.scheduler.common.task.Log4JTaskLogs in project scheduling by ow2-proactive.

the class TestTaskResultData method testLog4jLogs.

@Test
public void testLog4jLogs() throws Exception {
    InternalJob job = saveSingleTask(createDefaultTask("task"));
    InternalTask task = (InternalTask) job.getTasks().get(0);
    LinkedList<LoggingEvent> events = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.INFO, "info" + i, null));
        events.add(new LoggingEvent("", Logger.getLogger(TestTaskResultData.class), Level.ERROR, "error" + i, null));
    }
    TaskResultImpl result = new TaskResultImpl(null, "result", new Log4JTaskLogs(events, "0"), 0);
    dbManager.updateAfterTaskFinished(job, task, result);
    TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
    TaskLogs logs = restoredResult.getOutput();
    Assert.assertNotNull(logs);
    String logsString = logs.getStdoutLogs(false);
    Assert.assertTrue(logsString.contains("info0"));
    Assert.assertTrue(logsString.contains("info1"));
    Assert.assertTrue(logsString.contains("info2"));
    logsString = logs.getStderrLogs(false);
    Assert.assertTrue(logsString.contains("error0"));
    Assert.assertTrue(logsString.contains("error1"));
    Assert.assertTrue(logsString.contains("error2"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Log4JTaskLogs(org.ow2.proactive.scheduler.common.task.Log4JTaskLogs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 Log4JTaskLogs (org.ow2.proactive.scheduler.common.task.Log4JTaskLogs)2 TaskLogs (org.ow2.proactive.scheduler.common.task.TaskLogs)2 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)1 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)1 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)1 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)1 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)1