Search in sources :

Example 1 with FileAppender

use of org.apache.log4j.FileAppender in project hbase by apache.

the class LogMonitoring method getActiveLogFiles.

public static Set<File> getActiveLogFiles() throws IOException {
    Set<File> ret = Sets.newHashSet();
    Appender a;
    @SuppressWarnings("unchecked") Enumeration<Appender> e = Logger.getRootLogger().getAllAppenders();
    while (e.hasMoreElements()) {
        a = e.nextElement();
        if (a instanceof FileAppender) {
            FileAppender fa = (FileAppender) a;
            String filename = fa.getFile();
            ret.add(new File(filename));
        }
    }
    return ret;
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) File(java.io.File)

Example 2 with FileAppender

use of org.apache.log4j.FileAppender in project cpsolver by UniTime.

the class Test method setupLogging.

/**
     * Setup log4j logging
     * 
     * @param logFile  log file
     * @param debug true if debug messages should be logged (use -Ddebug=true to enable debug message)
     */
public static void setupLogging(File logFile, boolean debug) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
    if (!debug)
        root.setLevel(Level.INFO);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 3 with FileAppender

use of org.apache.log4j.FileAppender in project cpsolver by UniTime.

the class Test method setupLogging.

/**
     * Setup log4j logging
     * 
     * @param logFile  log file
     */
public static void setupLogging(File logFile) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 4 with FileAppender

use of org.apache.log4j.FileAppender in project intellij-community by JetBrains.

the class Runner method initLogger.

public static void initLogger() {
    if (logger == null) {
        long requiredFreeSpace = 1000000;
        String logFolder = getDir(requiredFreeSpace);
        FileAppender update = new FileAppender();
        update.setFile(new File(logFolder, "idea_updater.log").getAbsolutePath());
        update.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
        update.setThreshold(Level.ALL);
        update.setAppend(true);
        update.activateOptions();
        FileAppender updateError = new FileAppender();
        updateError.setFile(new File(logFolder, "idea_updater_error.log").getAbsolutePath());
        updateError.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
        updateError.setThreshold(Level.ERROR);
        updateError.setAppend(false);
        updateError.activateOptions();
        logger = Logger.getLogger("com.intellij.updater");
        logger.addAppender(updateError);
        logger.addAppender(update);
        logger.setLevel(Level.ALL);
        logger.info("--- Updater started ---");
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) ZipFile(java.util.zip.ZipFile)

Example 5 with FileAppender

use of org.apache.log4j.FileAppender in project symmetric-ds by JumpMind.

the class SnapshotUtil method findSymmetricLogFile.

@SuppressWarnings("unchecked")
public static Map<File, Layout> findSymmetricLogFile() {
    Enumeration<Appender> appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();
        if (appender instanceof FileAppender) {
            FileAppender fileAppender = (FileAppender) appender;
            if (fileAppender != null) {
                File file = new File(fileAppender.getFile());
                if (file != null && file.exists()) {
                    Map<File, Layout> matches = new HashMap<File, Layout>();
                    matches.put(file, fileAppender.getLayout());
                    return matches;
                }
            }
        }
    }
    return null;
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) HashMap(java.util.HashMap) Layout(org.apache.log4j.Layout) 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