blob: 80394b6b152d5bcaa0869b7bc34c0bd842508660 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2019 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package org.eclipse.app4mc.transformation.log4j.headless.configuration;
import java.io.File;
import org.apache.log4j.FileAppender;
/**
* Custom Log4j appender that is writing log statements to a dedicated log file
* if the system property <i>OUTPUT_DIRECTORY</i> is set. With this mechanism it
* is possible to write a log file per migration session to a dedicated log file
* only.
*/
public class TransformationFileAppender extends FileAppender {
@Override
protected boolean checkEntryConditions() {
// we only append if an output directory is set
String logFilePath = System.getProperty("APP4MC_TRANSFORMATION_LOG_FILE");
if (logFilePath != null) {
if (new File(logFilePath).canWrite()==false) {
return false;
}
super.setFile(logFilePath);
super.activateOptions();
return super.checkEntryConditions();
}
return false;
}
@Override
public void activateOptions() {
// simply avoid the log warning for missing fileName configuration
if (fileName != null) {
super.activateOptions();
}
}
}