Search in sources :

Example 1 with FileAppender

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);
}
Also used : FileAppender(org.ow2.proactive.utils.appenders.FileAppender) Logger(org.apache.log4j.Logger)

Example 2 with FileAppender

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;
}
Also used : FileAppender(org.apache.log4j.FileAppender) File(java.io.File) TaskLoggerRelativePathGenerator(org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)

Example 3 with FileAppender

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"));
}
Also used : FileAppender(org.ow2.proactive.utils.appenders.FileAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with FileAppender

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;
}
Also used : FileAppender(org.ow2.proactive.utils.appenders.FileAppender)

Aggregations

FileAppender (org.ow2.proactive.utils.appenders.FileAppender)3 File (java.io.File)2 IOException (java.io.IOException)1 FileAppender (org.apache.log4j.FileAppender)1 Logger (org.apache.log4j.Logger)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 Test (org.junit.Test)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 TaskLoggerRelativePathGenerator (org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)1 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)1