use of org.apache.log4j.FileAppender in project apex-core by apache.
the class LoggerUtil method getLogFileInformation.
/**
* Returns logger log file {@link LogFileInformation}
* @return logFileInformation
*/
public static LogFileInformation getLogFileInformation() {
FileAppender fileAppender = getFileAppender();
if (shouldFetchLogFileInformation(fileAppender)) {
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 apex-core by apache.
the class LoggerUtil method getFileAppender.
private static FileAppender getFileAppender() {
Enumeration<Appender> e = LogManager.getRootLogger().getAllAppenders();
FileAppender fileAppender = null;
while (e.hasMoreElements()) {
Appender appender = e.nextElement();
if (appender instanceof FileAppender) {
if (fileAppender == null) {
fileAppender = (FileAppender) appender;
} else {
//skip fetching log file information if we have multiple file Appenders
return null;
}
}
}
return fileAppender;
}
use of org.apache.log4j.FileAppender in project gocd by gocd.
the class BootstrapperLoggingHelper method setupDefaultLog4j.
private static void setupDefaultLog4j() {
String logFile = System.getenv("LOG_FILE");
System.out.println("logFile Environment Variable= " + logFile);
try {
if (logFile == null) {
logFile = "go-agent-bootstrapper.log";
}
System.out.println("Logging to " + logFile);
BasicConfigurator.configure(new FileAppender(LOG4J_PATTERN, logFile));
Logger.getRootLogger().setLevel(Level.INFO);
} catch (IOException e) {
BasicConfigurator.configure(new ConsoleAppender(LOG4J_PATTERN));
Logger.getRootLogger().setLevel(Level.INFO);
Log LOG = LogFactory.getLog(BootstrapperLoggingHelper.class);
LOG.warn("Unable to initialize log4j file-appender: " + logFile, e);
LOG.warn("Using console-appender instead");
}
}
use of org.apache.log4j.FileAppender in project honeycomb by altamiracorp.
the class Bootstrap method ensureLoggingPathsCorrect.
private static void ensureLoggingPathsCorrect() {
Enumeration<?> allAppenders = Logger.getRootLogger().getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender appender = (Appender) allAppenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String file = fileAppender.getFile();
if (file == null) {
continue;
}
File f = new File(file);
System.err.println("Testing: " + f.getName());
if (f.exists()) {
if (!f.canWrite()) {
System.err.println("Cannot write to " + f.getName());
}
} else {
String createFailure = "Could not create logging file " + f.getName();
try {
if (!f.createNewFile()) {
System.err.println(createFailure);
throw new RuntimeException(createFailure);
}
} catch (IOException e) {
System.err.println(createFailure);
throw new RuntimeException(createFailure, e);
}
}
}
}
}
use of org.apache.log4j.FileAppender in project JMRI by JMRI.
the class Log4JUtil method startupInfo.
@SuppressWarnings("unchecked")
public static String startupInfo(String program) {
log.info(jmriLog);
Enumeration<org.apache.log4j.Logger> e = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
while (e.hasMoreElements()) {
Appender a = (Appender) e.nextElement();
if (a instanceof RollingFileAppender) {
log.info("This log is appended to file: " + ((RollingFileAppender) a).getFile());
} else if (a instanceof FileAppender) {
log.info("This log is stored in file: " + ((FileAppender) a).getFile());
}
}
return (program + " version " + jmri.Version.name() + " starts under Java " + System.getProperty("java.version", "<unknown>") + " on " + System.getProperty("os.name", "<unknown>") + " " + System.getProperty("os.arch", "<unknown>") + " v" + System.getProperty("os.version", "<unknown>") + " at " + (new java.util.Date()));
}
Aggregations