Search in sources :

Example 11 with PatternLayout

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

the class StartupUtil method prepareAndStart.

static void prepareAndStart(String[] args, AppStarter appStarter) {
    boolean newConfigFolder = false;
    if (!Main.isHeadless()) {
        AppUIUtil.updateFrameClass();
        newConfigFolder = !new File(PathManager.getConfigPath()).exists();
    }
    if (!checkJdkVersion()) {
        System.exit(Main.JDK_CHECK_FAILED);
    }
    // avoiding "log4j:WARN No appenders could be found"
    System.setProperty("log4j.defaultInitOverride", "true");
    try {
        org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
        if (!root.getAllAppenders().hasMoreElements()) {
            root.setLevel(Level.WARN);
            root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN)));
        }
    } catch (Throwable e) {
        //noinspection CallToPrintStackTrace
        e.printStackTrace();
    }
    // note: uses config folder!
    if (!checkSystemFolders()) {
        System.exit(Main.DIR_CHECK_FAILED);
    }
    ActivationResult result = lockSystemFolders(args);
    if (result == ActivationResult.ACTIVATED) {
        System.exit(0);
    } else if (result != ActivationResult.STARTED) {
        System.exit(Main.INSTANCE_CHECK_FAILED);
    }
    if (newConfigFolder) {
        appStarter.beforeImportConfigs();
        ConfigImportHelper.importConfigsTo(PathManager.getConfigPath());
    }
    Logger.setFactory(LoggerFactory.class);
    Logger log = Logger.getInstance(Main.class);
    startLogging(log);
    loadSystemLibraries(log);
    fixProcessEnvironment(log);
    if (!Main.isHeadless()) {
        AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame());
        AppUIUtil.registerBundledFonts();
        AppUIUtil.showPrivacyPolicy();
    }
    appStarter.start(newConfigFolder);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) Logger(com.intellij.openapi.diagnostic.Logger) File(java.io.File)

Example 12 with PatternLayout

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

the class WithholdingAppender method install.

/**
     * Install the WithholdingAppender, essentially muting all logging 
     * and withholding it until release() is called
     * @return the WithholdingAppender that can be used to get the 
     * withheld log output
     */
public static WithholdingAppender install() {
    LogManager.getRootLogger().removeAllAppenders();
    final WithholdingAppender withholdingAppender = new WithholdingAppender(new PatternLayout("%d{dd.MM.yyyy HH:mm:ss.SSS} *%-5p* [%t] %c{1}: %m\n"));
    LogManager.getRootLogger().addAppender(withholdingAppender);
    return withholdingAppender;
}
Also used : PatternLayout(org.apache.log4j.PatternLayout)

Example 13 with PatternLayout

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

the class TestStreamAppender method testSystemProducerAppenderInAM.

@Test
public void testSystemProducerAppenderInAM() {
    System.setProperty("samza.container.name", "samza-job-coordinator");
    MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
    PatternLayout layout = new PatternLayout();
    layout.setConversionPattern("%m");
    systemProducerAppender.setLayout(layout);
    systemProducerAppender.activateOptions();
    log.addAppender(systemProducerAppender);
    log.info("no-received");
    systemProducerAppender.flushSystemProducer();
    // it should not receive anything because the system is not setup
    assertEquals(0, MockSystemProducer.messagesReceived.size());
    systemProducerAppender.setupSystem();
    MockSystemProducerAppender.systemInitialized = true;
    log.info("testing3");
    log.info("testing4");
    systemProducerAppender.flushSystemProducer();
    // be able to received msgs now
    assertEquals(2, MockSystemProducer.messagesReceived.size());
    assertTrue(new String((byte[]) MockSystemProducer.messagesReceived.get(0)).contains("\"message\":\"testing3\""));
    assertTrue(new String((byte[]) MockSystemProducer.messagesReceived.get(1)).contains("\"message\":\"testing4\""));
    // reset
    log.removeAllAppenders();
    MockSystemProducer.messagesReceived.clear();
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) Test(org.junit.Test)

Example 14 with PatternLayout

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

the class TestStreamAppender method testDefaultSerde.

@Test
public void testDefaultSerde() {
    System.setProperty("samza.container.name", "samza-container-1");
    MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
    PatternLayout layout = new PatternLayout();
    layout.setConversionPattern("%m");
    systemProducerAppender.setLayout(layout);
    systemProducerAppender.activateOptions();
    assertNotNull(systemProducerAppender.getSerde());
    assertEquals(LoggingEventJsonSerde.class, systemProducerAppender.getSerde().getClass());
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) Test(org.junit.Test)

Example 15 with PatternLayout

use of org.apache.log4j.PatternLayout 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{ISO8601}][%-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)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)106 ConsoleAppender (org.apache.log4j.ConsoleAppender)49 Logger (org.apache.log4j.Logger)30 IOException (java.io.IOException)20 Appender (org.apache.log4j.Appender)20 FileAppender (org.apache.log4j.FileAppender)17 File (java.io.File)14 Layout (org.apache.log4j.Layout)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)12 WriterAppender (org.apache.log4j.WriterAppender)9 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)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