use of org.apache.log4j.FileAppender in project apex-core by apache.
the class LoggerUtil method getLogFileInformation.
public static LogFileInformation getLogFileInformation(Logger logger) {
if (logger == null) {
logger = LogManager.getRootLogger();
}
FileAppender fileAppender = getFileAppender(logger);
if (fileAppender != null) {
File logFile = new File(fileAppender.getFile());
LogFileInformation logFileInfo = new LogFileInformation(fileAppender.getFile(), logFile.length());
return logFileInfo;
}
return null;
}
use of org.apache.log4j.FileAppender in project alluxio by Alluxio.
the class BaseIntegrationTest method logHandler.
private TestWatcher logHandler() {
return new TestWatcher() {
private String mLogPath;
private Appender mAppender;
@Override
protected void starting(Description description) {
try {
mLogPath = logPath(description);
// In case the file already exists, truncate it.
new FileWriter(mLogPath).close();
mAppender = new FileAppender(new PatternLayout("%d{ISO8601} [%t] %-5p %c{2} (%F:%M) - %m%n"), mLogPath);
LogManager.getRootLogger().addAppender(mAppender);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected void succeeded(Description description) {
try {
Files.delete(Paths.get(mLogPath));
} catch (Throwable t) {
LOG.error("Failed to delete success log file {}", mLogPath);
}
}
@Override
protected void skipped(AssumptionViolatedException e, Description description) {
succeeded(description);
}
@Override
protected void finished(Description description) {
LogManager.getRootLogger().removeAppender(mAppender);
}
private String logPath(Description description) {
String basename = String.format("tests-%s-%s.log", description.getClassName(), description.getMethodName());
return PathUtils.concatPath(Constants.TEST_LOG_DIR, basename);
}
};
}
use of org.apache.log4j.FileAppender in project gerrit by GerritCodeReview.
the class SystemLog method createAppender.
public static Appender createAppender(Path logdir, String name, Layout layout, boolean rotate) {
final FileAppender dst = rotate ? new DailyRollingFileAppender() : new FileAppender();
dst.setName(name);
dst.setLayout(layout);
dst.setEncoding(UTF_8.name());
dst.setFile(resolve(logdir).resolve(name).toString());
dst.setImmediateFlush(true);
dst.setAppend(true);
dst.setErrorHandler(new DieErrorHandler());
dst.activateOptions();
dst.setErrorHandler(new OnlyOnceErrorHandler());
return dst;
}
use of org.apache.log4j.FileAppender in project databus by linkedin.
the class TestUtil method setupLogging.
public static void setupLogging(boolean logToConsole, String fileLogPath, Level logLevel) {
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} [%t] (%p) {%c{1}} %m%n");
Logger.getRootLogger().removeAllAppenders();
if (logToConsole) {
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().addAppender(defaultAppender);
}
if (null != fileLogPath && 0 < fileLogPath.length()) {
File logFile = new File(fileLogPath);
if (null != logFile.getParentFile() && !logFile.getParentFile().exists()) {
if (!logFile.getParentFile().mkdirs()) {
Logger.getRootLogger().error("unable to create parent directory for log file: " + logFile);
}
}
FileAppender fileAppender = null;
try {
fileAppender = new FileAppender(defaultLayout, fileLogPath);
} catch (IOException io) {
Logger.getRootLogger().error(io);
}
if (null != fileAppender)
Logger.getRootLogger().addAppender(fileAppender);
}
Logger.getRootLogger().setLevel(logLevel);
}
use of org.apache.log4j.FileAppender in project ignite by apache.
the class GridTestLog4jLogger method setApplicationAndNode.
/**
* {@inheritDoc}
*/
@Override
public void setApplicationAndNode(@Nullable String application, UUID nodeId) {
A.notNull(nodeId, "nodeId");
this.nodeId = nodeId;
for (FileAppender a : fileAppenders) {
if (a instanceof LoggerNodeIdAndApplicationAware) {
((LoggerNodeIdAndApplicationAware) a).setApplicationAndNode(application, nodeId);
a.activateOptions();
}
}
}
Aggregations