Search in sources :

Example 46 with PatternLayout

use of org.apache.log4j.PatternLayout in project ignite by apache.

the class GridLog4jCorrectFileNameTest method createAppender.

/**
 * Creates new GridLog4jRollingFileAppender.
 *
 * @return GridLog4jRollingFileAppender.
 */
private static Log4jRollingFileAppender createAppender() {
    Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
    appender.setLayout(new PatternLayout("[%d{ISO8601}][%-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 47 with PatternLayout

use of org.apache.log4j.PatternLayout in project metron by apache.

the class UnitTestHelper method verboseLogging.

public static void verboseLogging(String pattern, Level level) {
    // create appender
    ConsoleAppender console = new ConsoleAppender();
    // configure the appender
    console.setLayout(new PatternLayout(pattern));
    console.setThreshold(level);
    console.activateOptions();
    // add appender to any Logger (here is root)
    Logger.getRootLogger().addAppender(console);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout)

Example 48 with PatternLayout

use of org.apache.log4j.PatternLayout in project knime-core by knime.

the class NodeLogger method addKNIMEConsoleWriter.

/**
 * Adds a new {@link java.io.Writer} with the given level to this logger.
 *
 * @param writer The writer to add.
 * @param minLevel The minimum level to output.
 * @param maxLevel The maximum level to output.
 * @since 2.12
 */
public static void addKNIMEConsoleWriter(final Writer writer, final LEVEL minLevel, final LEVEL maxLevel) {
    final Appender a = Logger.getRootLogger().getAppender(KNIME_CONSOLE_APPENDER);
    final Layout layout;
    if (a != null) {
        layout = a.getLayout();
        checkLayoutFlags(layout);
    } else {
        layout = WF_DIR_LOG_FILE_LAYOUT;
    }
    // no stack traces in KNIME's console view:
    // a custom layout that pretends Throwable information is baked into the log message
    final Layout suppressThrowableLayout = new Layout() {

        @Override
        public void activateOptions() {
            layout.activateOptions();
        }

        @Override
        public String format(final LoggingEvent event) {
            return layout.format(event);
        }

        @Override
        public boolean ignoresThrowable() {
            // PatternLayout returns true (which makes the appender to log the Throwable)
            return false;
        }
    };
    addWriter(writer, suppressThrowableLayout, minLevel, maxLevel);
}
Also used : WriterAppender(org.apache.log4j.WriterAppender) LogfileAppender(org.knime.core.util.LogfileAppender) NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout)

Example 49 with PatternLayout

use of org.apache.log4j.PatternLayout in project scheduling by ow2-proactive.

the class RMNodeUpdater method initLogger.

private static Logger initLogger() {
    if (System.getProperty("log4j.configuration") == null) {
        // While logger is not configured and it not set with sys properties, use Console logger
        Logger.getRootLogger().getLoggerRepository().resetConfiguration();
        BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%m%n")));
        Logger.getRootLogger().setLevel(Level.INFO);
    }
    return Logger.getLogger(RMNodeUpdater.class);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout)

Example 50 with PatternLayout

use of org.apache.log4j.PatternLayout in project scheduling by ow2-proactive.

the class AOSynchronizationTest method classInit.

@BeforeClass
public static void classInit() {
    CentralPAPropertyRepository.PA_CLASSLOADING_USEHTTP.setValue(false);
    if (System.getProperty("log4j.configuration") == null) {
        // While logger is not configured and it not set with sys properties, use Console logger
        Logger.getRootLogger().getLoggerRepository().resetConfiguration();
        BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%m%n")));
        Logger.getRootLogger().setLevel(Level.INFO);
    }
    Logger.getLogger(AOSynchronization.class).setLevel(Level.TRACE);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) BeforeClass(org.junit.BeforeClass)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)101 ConsoleAppender (org.apache.log4j.ConsoleAppender)51 Logger (org.apache.log4j.Logger)27 IOException (java.io.IOException)21 Appender (org.apache.log4j.Appender)18 FileAppender (org.apache.log4j.FileAppender)17 Layout (org.apache.log4j.Layout)15 File (java.io.File)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)6 WriterAppender (org.apache.log4j.WriterAppender)6