use of org.apache.log4j.FileAppender in project dubbo by alibaba.
the class Log4jContainer method start.
@SuppressWarnings("unchecked")
public void start() {
String file = ConfigUtils.getProperty(LOG4J_FILE);
if (file != null && file.length() > 0) {
String level = ConfigUtils.getProperty(LOG4J_LEVEL);
if (level == null || level.length() == 0) {
level = DEFAULT_LOG4J_LEVEL;
}
Properties properties = new Properties();
properties.setProperty("log4j.rootLogger", level + ",application");
properties.setProperty("log4j.appender.application", "org.apache.log4j.DailyRollingFileAppender");
properties.setProperty("log4j.appender.application.File", file);
properties.setProperty("log4j.appender.application.Append", "true");
properties.setProperty("log4j.appender.application.DatePattern", "'.'yyyy-MM-dd");
properties.setProperty("log4j.appender.application.layout", "org.apache.log4j.PatternLayout");
properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n");
PropertyConfigurator.configure(properties);
}
String subdirectory = ConfigUtils.getProperty(LOG4J_SUBDIRECTORY);
if (subdirectory != null && subdirectory.length() > 0) {
Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers();
while (ls.hasMoreElements()) {
org.apache.log4j.Logger l = ls.nextElement();
if (l != null) {
Enumeration<Appender> as = l.getAllAppenders();
while (as.hasMoreElements()) {
Appender a = as.nextElement();
if (a instanceof FileAppender) {
FileAppender fa = (FileAppender) a;
String f = fa.getFile();
if (f != null && f.length() > 0) {
int i = f.replace('\\', '/').lastIndexOf('/');
String path;
if (i == -1) {
path = subdirectory;
} else {
path = f.substring(0, i);
if (!path.endsWith(subdirectory)) {
path = path + "/" + subdirectory;
}
f = f.substring(i + 1);
}
fa.setFile(path + "/" + f);
fa.activateOptions();
}
}
}
}
}
}
}
use of org.apache.log4j.FileAppender in project scheduling by ow2-proactive.
the class ActiveActor method rebaseLogFiles.
/**
* Log4j configuration tweaking
* This method will modify the file name of every FileAppender
* by adding the hostname of the machine onto which it executes.
* Because it cannot be done from the log4j-configuration file
* we hard-code this configuration issue
* @param logger2
*/
private void rebaseLogFiles() {
Enumeration<Logger> curLoggers = LogManager.getCurrentLoggers();
while (curLoggers.hasMoreElements()) {
Logger someLogger = curLoggers.nextElement();
Enumeration<Appender> appenders = someLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender app = appenders.nextElement();
if (app instanceof FileAppender) {
FileAppender fileApp = (FileAppender) app;
System.out.println("File appender, output file " + fileApp.getFile());
addHostToFilename(fileApp);
}
}
}
}
use of org.apache.log4j.FileAppender in project ripme by RipMeApp.
the class MainWindow method setLogLevel.
private void setLogLevel(String level) {
Level newLevel = Level.ERROR;
level = level.substring(level.lastIndexOf(' ') + 1);
switch(level) {
case "Debug":
newLevel = Level.DEBUG;
break;
case "Info":
newLevel = Level.INFO;
break;
case "Warn":
newLevel = Level.WARN;
break;
case "Error":
newLevel = Level.ERROR;
break;
}
Logger.getRootLogger().setLevel(newLevel);
logger.setLevel(newLevel);
ConsoleAppender ca = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
if (ca != null) {
ca.setThreshold(newLevel);
}
FileAppender fa = (FileAppender) Logger.getRootLogger().getAppender("FILE");
if (fa != null) {
fa.setThreshold(newLevel);
}
}
use of org.apache.log4j.FileAppender in project ripme by RipMeApp.
the class AbstractRipper method setup.
/**
* Sets ripper's:
* Working directory
* Logger (for debugging)
* FileAppender
* Threadpool
* @throws IOException
* Always be prepared.
*/
public void setup() throws IOException {
setWorkingDir(this.url);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
fa.setFile(this.workingDir + File.separator + "log.txt");
fa.activateOptions();
}
this.threadPool = new DownloadThreadPool();
}
use of org.apache.log4j.FileAppender in project ripme by RipMeApp.
the class AbstractRipper method checkIfComplete.
/**
* Notifies observers and updates state if all files have been ripped.
*/
void checkIfComplete() {
if (observer == null) {
logger.debug("observer is null");
return;
}
if (!completed) {
completed = true;
logger.info(" Rip completed!");
RipStatusComplete rsc = new RipStatusComplete(workingDir, getCount());
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, rsc);
observer.update(this, msg);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
logger.debug("Changing log file back to 'ripme.log'");
fa.setFile("ripme.log");
fa.activateOptions();
}
if (Utils.getConfigBoolean("urls_only.save", false)) {
String urlFile = this.workingDir + File.separator + "urls.txt";
try {
Desktop.getDesktop().open(new File(urlFile));
} catch (IOException e) {
logger.warn("Error while opening " + urlFile, e);
}
}
}
}
Aggregations