Search in sources :

Example 6 with FileAppender

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;
}
Also used : FileAppender(org.apache.log4j.FileAppender) LogFileInformation(org.apache.apex.log.LogFileInformation) File(java.io.File)

Example 7 with FileAppender

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

Example 8 with 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");
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) Log(org.apache.commons.logging.Log) IOException(java.io.IOException)

Example 9 with FileAppender

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

Example 10 with FileAppender

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

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