Search in sources :

Example 11 with FileAppender

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();
                        }
                    }
                }
            }
        }
    }
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) Properties(java.util.Properties)

Example 12 with FileAppender

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

Example 13 with FileAppender

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);
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) Level(org.apache.log4j.Level)

Example 14 with FileAppender

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

Example 15 with FileAppender

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);
            }
        }
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) RipStatusComplete(com.rarchives.ripme.ui.RipStatusComplete) RipStatusMessage(com.rarchives.ripme.ui.RipStatusMessage) Logger(org.apache.log4j.Logger) File(java.io.File)

Aggregations

FileAppender (org.apache.log4j.FileAppender)47 Appender (org.apache.log4j.Appender)18 File (java.io.File)15 IOException (java.io.IOException)14 PatternLayout (org.apache.log4j.PatternLayout)14 Logger (org.apache.log4j.Logger)12 ConsoleAppender (org.apache.log4j.ConsoleAppender)8 Layout (org.apache.log4j.Layout)5 Enumeration (java.util.Enumeration)4 Properties (java.util.Properties)4 FileNotFoundException (java.io.FileNotFoundException)3 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)3 RollingFileAppender (org.apache.log4j.RollingFileAppender)3 SimpleLayout (org.apache.log4j.SimpleLayout)3 InputStream (java.io.InputStream)2 HTMLLayout (org.apache.log4j.HTMLLayout)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 LoggerChannel (com.biglybt.pif.logging.LoggerChannel)1 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)1 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1