Search in sources :

Example 1 with LevelRangeFilter

use of org.apache.log4j.varia.LevelRangeFilter in project ignite by apache.

the class GridCacheAbstractLoadTest method initLogger.

/**
     * Initializes logger.
     *
     * @param log Log file name.
     * @return Logger.
     * @throws IgniteCheckedException If file initialization failed.
     */
protected IgniteLogger initLogger(String log) throws IgniteCheckedException {
    Logger impl = Logger.getRootLogger();
    impl.removeAllAppenders();
    String fileName = U.getIgniteHome() + "/work/log/" + log;
    // Configure output that should go to System.out
    RollingFileAppender fileApp;
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    try {
        fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
        fileApp.setMaxBackupIndex(0);
        fileApp.setAppend(false);
        // fileApp.rollOver();
        fileApp.activateOptions();
    } catch (IOException e) {
        throw new IgniteCheckedException("Unable to initialize file appender.", e);
    }
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    fileApp.addFilter(lvlFilter);
    impl.addAppender(fileApp);
    // Configure output that should go to System.out
    ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    lvlFilter.setLevelMax(Level.INFO);
    conApp.addFilter(lvlFilter);
    conApp.activateOptions();
    impl.addAppender(conApp);
    // Configure output that should go to System.err
    conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
    conApp.setThreshold(Level.WARN);
    conApp.activateOptions();
    impl.addAppender(conApp);
    impl.setLevel(Level.INFO);
    return new GridTestLog4jLogger(false);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter) IOException(java.io.IOException) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.log4j.Logger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 2 with LevelRangeFilter

use of org.apache.log4j.varia.LevelRangeFilter in project ignite by apache.

the class GridSingleExecutionTest method initLogger.

/**
     * Initializes logger.
     *
     * @param log Log file name.
     * @return Logger.
     * @throws IgniteCheckedException If file initialization failed.
     */
private static IgniteLogger initLogger(String log) throws IgniteCheckedException {
    Logger impl = Logger.getRootLogger();
    impl.removeAllAppenders();
    String fileName = U.getIgniteHome() + "/work/log/" + log;
    // Configure output that should go to System.out
    RollingFileAppender fileApp;
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    try {
        fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
        fileApp.setMaxBackupIndex(0);
        fileApp.rollOver();
    } catch (IOException e) {
        throw new IgniteCheckedException("Unable to initialize file appender.", e);
    }
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    fileApp.addFilter(lvlFilter);
    impl.addAppender(fileApp);
    // Configure output that should go to System.out
    ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.INFO);
    lvlFilter.setLevelMax(Level.INFO);
    conApp.addFilter(lvlFilter);
    impl.addAppender(conApp);
    // Configure output that should go to System.err
    conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
    conApp.setThreshold(Level.WARN);
    impl.addAppender(conApp);
    impl.setLevel(Level.INFO);
    Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG);
    return new GridTestLog4jLogger(false);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter) IOException(java.io.IOException) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.log4j.Logger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 3 with LevelRangeFilter

use of org.apache.log4j.varia.LevelRangeFilter in project ignite by apache.

the class Log4JLogger method createConsoleAppender.

/**
     * Creates console appender with some reasonable default logging settings.
     *
     * @param maxLevel Max logging level.
     * @return New console appender.
     */
private Appender createConsoleAppender(Level maxLevel) {
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    // Configure output that should go to System.out
    Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.TRACE);
    lvlFilter.setLevelMax(maxLevel);
    app.addFilter(lvlFilter);
    return app;
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Example 4 with LevelRangeFilter

use of org.apache.log4j.varia.LevelRangeFilter in project ignite by apache.

the class GridLog4jCorrectFileNameTest method createAppender.

/**
     * Creates new GridLog4jRollingFileAppender.
     *
     * @return GridLog4jRollingFileAppender.
     * @throws Exception If error occurred.
     */
private static Log4jRollingFileAppender createAppender() throws Exception {
    Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
    appender.setLayout(new PatternLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"));
    appender.setFile("work/log/ignite.log");
    appender.setName(Log4jRollingFileAppender.class.getSimpleName());
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    lvlFilter.setLevelMax(Level.INFO);
    appender.addFilter(lvlFilter);
    return appender;
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Example 5 with LevelRangeFilter

use of org.apache.log4j.varia.LevelRangeFilter in project ignite by apache.

the class GridTestLog4jLogger method createConsoleAppender.

/**
     * Creates console appender with some reasonable default logging settings.
     *
     * @param maxLevel Max logging level.
     * @return New console appender.
     */
private Appender createConsoleAppender(Level maxLevel) {
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    // Configure output that should go to System.out
    Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.TRACE);
    lvlFilter.setLevelMax(maxLevel);
    app.addFilter(lvlFilter);
    return app;
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)5 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)5 ConsoleAppender (org.apache.log4j.ConsoleAppender)4 IOException (java.io.IOException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)2 Appender (org.apache.log4j.Appender)2 FileAppender (org.apache.log4j.FileAppender)2 Logger (org.apache.log4j.Logger)2 RollingFileAppender (org.apache.log4j.RollingFileAppender)2