use of org.ow2.proactive.utils.appenders.FileAppender in project scheduling by ow2-proactive.
the class ServerJobAndTaskLogs method addNewFileAppenderToLoggerFor.
private static void addNewFileAppenderToLoggerFor(Class<?> cls) {
Logger jobLogger = Logger.getLogger(cls);
FileAppender appender = createFileAppender();
jobLogger.addAppender(appender);
}
use of org.ow2.proactive.utils.appenders.FileAppender in project scheduling by ow2-proactive.
the class TaskLogger method createFileAppender.
public File createFileAppender(File pathToFolder) throws IOException {
if (taskLogAppender.getAppender(FILE_APPENDER_NAME) != null) {
throw new IllegalStateException("Only one file appender can be created");
}
File logFile = new File(pathToFolder, new TaskLoggerRelativePathGenerator(taskId).getRelativePath());
logFile.getParentFile().mkdirs();
FileUtils.touch(logFile);
logFile.setWritable(true, false);
FileAppender fap = new FileAppender(Log4JTaskLogs.getTaskLogLayout(), logFile.getAbsolutePath(), false);
fap.setName(FILE_APPENDER_NAME);
taskLogAppender.addAppender(fap);
return logFile;
}
use of org.ow2.proactive.utils.appenders.FileAppender in project scheduling by ow2-proactive.
the class TaskLoggerTest method testFileAppender.
@Test
public void testFileAppender() throws IOException {
JobId jobId = new JobIdImpl(1123, "readableName");
TaskId taskId = TaskIdImpl.createTaskId(jobId, "taskreadableName", 123123);
FileAppender appender = new FileAppender();
File logFolder = folder.newFolder("logs");
File logFile = new File(logFolder, TaskLogger.getTaskLogRelativePath(taskId));
appender.setFilesLocation(logFolder.getAbsolutePath());
try {
appender.append(TaskLogger.getTaskLogRelativePath(taskId), new LoggingEvent("mylogger", Logger.getRootLogger(), Level.INFO, "HelloWorld", null));
} catch (Exception e) {
Assert.fail(e);
}
assertTrue(FileUtils.readFileToString(logFile, Charset.defaultCharset()).contains("HelloWorld"));
}
use of org.ow2.proactive.utils.appenders.FileAppender in project scheduling by ow2-proactive.
the class ServerJobAndTaskLogs method createFileAppender.
private static FileAppender createFileAppender() {
FileAppender appender = new FileAppender();
if (PASchedulerProperties.SCHEDULER_JOB_LOGS_MAX_SIZE.isSet()) {
appender.setMaxFileSize(PASchedulerProperties.SCHEDULER_JOB_LOGS_MAX_SIZE.getValueAsString());
}
appender.setFilesLocation(getLogsLocation());
return appender;
}
Aggregations