Search in sources :

Example 46 with FileAppender

use of org.apache.log4j.FileAppender in project databus by linkedin.

the class TestUtil method setupLogging.

public static void setupLogging(boolean logToConsole, String fileLogPath, Level logLevel) {
    PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} [%t] (%p) {%c{1}} %m%n");
    Logger.getRootLogger().removeAllAppenders();
    if (logToConsole) {
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
        Logger.getRootLogger().addAppender(defaultAppender);
    }
    if (null != fileLogPath && 0 < fileLogPath.length()) {
        File logFile = new File(fileLogPath);
        if (null != logFile.getParentFile() && !logFile.getParentFile().exists()) {
            if (!logFile.getParentFile().mkdirs()) {
                Logger.getRootLogger().error("unable to create parent directory for log file: " + logFile);
            }
        }
        FileAppender fileAppender = null;
        try {
            fileAppender = new FileAppender(defaultLayout, fileLogPath);
        } catch (IOException io) {
            Logger.getRootLogger().error(io);
        }
        if (null != fileAppender)
            Logger.getRootLogger().addAppender(fileAppender);
    }
    Logger.getRootLogger().setLevel(logLevel);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) File(java.io.File)

Example 47 with FileAppender

use of org.apache.log4j.FileAppender in project smscgateway by RestComm.

the class TestHarness method init.

public void init() {
    try {
        Properties tckProperties = new Properties();
        InputStream inStreamLog4j = TestHarness.class.getResourceAsStream("/log4j.properties");
        System.out.println("Input Stream = " + inStreamLog4j);
        Properties propertiesLog4j = new Properties();
        try {
            propertiesLog4j.load(inStreamLog4j);
            PropertyConfigurator.configure(propertiesLog4j);
        } catch (IOException e) {
            e.printStackTrace();
            BasicConfigurator.configure();
        }
        logger.debug("log4j configured");
        String lf = System.getProperties().getProperty(LOG_FILE_NAME);
        if (lf != null) {
            logFileName = lf;
        }
        // If already created a print writer then just use it.
        try {
            logger.addAppender(new FileAppender(new SimpleLayout(), logFileName));
        } catch (FileNotFoundException fnfe) {
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) SimpleLayout(org.apache.log4j.SimpleLayout) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 48 with FileAppender

use of org.apache.log4j.FileAppender in project smscgateway by RestComm.

the class SMPPp method initLog4J.

private void initLog4J(Properties props) {
    try {
        String log4jProps = props.getProperty("smppp.log4jPropsFilePath");
        if (log4jProps != null) {
            InputStream inStreamLog4j = new FileInputStream(new File(log4jProps));
            Properties propertiesLog4j = new Properties();
            propertiesLog4j.load(inStreamLog4j);
            PropertyConfigurator.configure(propertiesLog4j);
        } else {
            BasicConfigurator.configure();
        }
        String lf = props.getProperty("smppp.logFilePath");
        if (lf != null) {
            ctx.logger.addAppender(new FileAppender(new SimpleLayout(), lf));
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) SimpleLayout(org.apache.log4j.SimpleLayout) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

FileAppender (org.apache.log4j.FileAppender)48 Appender (org.apache.log4j.Appender)19 File (java.io.File)15 IOException (java.io.IOException)15 PatternLayout (org.apache.log4j.PatternLayout)14 Logger (org.apache.log4j.Logger)12 ConsoleAppender (org.apache.log4j.ConsoleAppender)8 Enumeration (java.util.Enumeration)5 Layout (org.apache.log4j.Layout)5 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 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)2 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