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));
}
}
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"));
}
Aggregations