Java Code Examples for org.apache.log4j.ConsoleAppender

The following examples show how to use org.apache.log4j.ConsoleAppender. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: yb-sample-apps   Source File: LogUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void configureLogLevel(boolean verbose) {
  // First remove all appenders.
  Logger.getLogger("com.yugabyte.sample").removeAppender("YBConsoleLogger");
  Logger.getRootLogger().removeAppender("YBConsoleLogger");;

  // Create the console appender.
  ConsoleAppender console = new ConsoleAppender();
  console.setName("YBConsoleLogger");
  String PATTERN = "%d [%p|%c|%C{1}] %m%n";
  console.setLayout(new PatternLayout(PATTERN));
  console.setThreshold(verbose ? Level.DEBUG : Level.INFO);
  console.activateOptions();

  // Set the desired logging level.
  if (verbose) {
    // If verbose, make everything DEBUG log level and output to console.
    Logger.getRootLogger().addAppender(console);
    Logger.getRootLogger().setLevel(Level.DEBUG);
  } else {
    // If not verbose, allow YB sample app and driver INFO logs go to console.
    Logger.getLogger("com.yugabyte.sample").addAppender(console);
    Logger.getLogger("com.yugabyte.driver").addAppender(console);
    Logger.getLogger("com.datastax.driver").addAppender(console);
    Logger.getRootLogger().setLevel(Level.WARN);
  }
}
 
Example 2
Source Project: jpeek   Source File: Main.java    License: MIT License 6 votes vote down vote up
/**
 * Run it.
 * @throws IOException If fails
 */
private void run() throws IOException {
    if (this.overwrite && this.sources.equals(this.target)) {
        throw new IllegalArgumentException(
            "Invalid paths - can't be equal if overwrite option is set."
        );
    }
    final ConsoleAppender console = this.buildConsoleAppender();
    final Map<String, Object> params = this.buildParameters();
    new App(
        this.sources.toPath(),
        new FileTarget(
            this.target,
            this.overwrite
        ).toPath(),
        params
    ).analyze();
    if (!this.quiet) {
        Logger.getRootLogger().removeAppender(console);
    }
}
 
Example 3
Source Project: astor   Source File: BaseEvolutionaryTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Logger createCustomFileLogger(String file) throws IOException {
	// ----
	ConsoleAppender console = new ConsoleAppender();
	String PATTERN = "%m%n-%c: ";
	console.setLayout(new PatternLayout(PATTERN));
	console.setThreshold(Level.INFO);
	console.activateOptions();
	Logger log = Logger.getLogger(Thread.currentThread().getName());

	log.getLoggerRepository().resetConfiguration();
	log.removeAllAppenders();
	log.addAppender(console);
	// ----
	org.apache.log4j.RollingFileAppender rfa = new RollingFileAppender(new org.apache.log4j.PatternLayout(PATTERN),
			file);
	log.addAppender(rfa);
	rfa.setImmediateFlush(true);

	return log;

}
 
Example 4
/**
 * Test Class setup
 */
@BeforeClass
public static void init() {

    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 300000; /* 300 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    SWTBotUtils.closeView("welcome", fBot);
    /* Switch perspectives */
    SWTBotUtils.switchToPerspective(NETWORK_PERSPECTIVE_ID);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 5
/**
 * Things to setup
 */
@BeforeClass
public static void beforeClass() {

    SWTBotUtils.initialize();
    Thread.currentThread().setName("SWTBotTest");
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

    fBot = new SWTWorkbenchBot();

    loadXmlFile();
    openTrace();
}
 
Example 6
/**
 * Before Class
 */
@BeforeClass
public static void beforeClass() {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.closeView("welcome", fBot);
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 7
/**
 * Before Class
 */
@BeforeClass
public static void beforeClass() {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

    /* set up test trace */
    setUpTrace();

}
 
Example 8
/**
 * Before Class
 */
@BeforeClass
public static void beforeClass() {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.closeView("welcome", fBot);
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 9
/** Test Class setup */
@BeforeClass
public static void init() {
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    SWTBotUtils.initialize();
    Thread.currentThread().setName(SWT_BOT_THREAD_NAME); // for the debugger
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
    fBot = new SWTWorkbenchBot();

    /* finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

}
 
Example 10
Source Project: tracecompass   Source File: FontEventEditorTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test Class setup
 */
@BeforeClass
public static void init() {
    SWTBotUtils.initialize();

    /* set up test trace */
    URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
    URI uri;
    try {
        uri = FileLocator.toFileURL(location).toURI();
        fTestFile = new File(uri);
    } catch (URISyntaxException | IOException e) {
        fail(e.getMessage());
    }

    assumeTrue(fTestFile.exists());

    /* Set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 11
Source Project: tracecompass   Source File: TmfAlignTimeAxisTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Initialization, creates a temp trace
 *
 * @throws IOException
 *             should not happen
 */
@BeforeClass
public static void init() throws IOException {
    SWTBotUtils.initialize();
    Thread.currentThread().setName("SWTBot Thread"); // for the debugger
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
    SWTWorkbenchBot bot = new SWTWorkbenchBot();

    /* finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
    fLocation = File.createTempFile("sample", ".xml");
    try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fLocation, "rw")) {
        braf.writeBytes(TRACE_START);
        for (int i = 0; i < NUM_EVENTS; i++) {
            braf.writeBytes(makeEvent(i * 100, i % 4));
        }
        braf.writeBytes(TRACE_END);
    }
    SWTBotUtils.createProject(PROJET_NAME);
    SWTBotUtils.selectTracesFolder(bot, PROJET_NAME);
}
 
Example 12
Source Project: tracecompass   Source File: TestTraceOffsetting.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Initialization, creates a temp trace
 *
 * @throws IOException
 *             should not happen
 */
@Before
public void init() throws IOException {
    SWTBotUtils.initialize();
    Thread.currentThread().setName("SWTBot Thread"); // for the debugger
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
    fBot = new SWTWorkbenchBot();

    IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00");
    TmfTimestampFormat.updateDefaultFormats();

    /* finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
    fLocation = File.createTempFile("sample", ".xml");
    try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fLocation, "rw")) {
        braf.writeBytes(TRACE_START);
        for (int i = 0; i < NUM_EVENTS; i++) {
            braf.writeBytes(makeEvent(i * 100, i % 4));
        }
        braf.writeBytes(TRACE_END);
    }
}
 
Example 13
/**
 * Test Class setup
 */
@BeforeClass
public static void init() {
    SWTBotUtils.initialize();

    /* set up test trace */
    URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
    URI uri;
    try {
        uri = FileLocator.toFileURL(location).toURI();
        fTestFile = new File(uri);
    } catch (URISyntaxException | IOException e) {
        fail(e.getMessage());
    }

    assumeTrue(fTestFile.exists());

    /* Set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 14
Source Project: tracecompass   Source File: FilterViewerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Initialization, creates a temp trace
 *
 * @throws IOException
 *             should not happen
 */
@BeforeClass
public static void init() throws IOException {
    IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00");
    TmfTimestampFormat.updateDefaultFormats();

    SWTBotUtils.initialize();
    Thread.currentThread().setName("SWTBot Thread"); // for the debugger
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
    fBot = new SWTWorkbenchBot();

    /* finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
    fFileLocation = File.createTempFile("sample", ".xml");
    try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) {
        braf.writeBytes(TRACE_START);
        for (int i = 0; i < 100; i++) {
            braf.writeBytes(makeEvent(i * 100, i % 4));
        }
        braf.writeBytes(TRACE_END);
    }
}
 
Example 15
/**
 * Test Class setup
 *
 * @throws Exception
 *             on error
 */
@BeforeClass
public static void init() throws Exception {
    TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);

    SWTBotUtils.initialize();

    /* Set up for SWTBot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
    fTracesFolder = new File(Objects.requireNonNull(TmfProjectRegistry.getProject(project, true).getTracesFolder()).getResource().getLocation().toOSString());

    createCProject(C_PROJECT_NAME);
    setTracingNature(C_PROJECT_NAME);
    IProject cProject = ResourcesPlugin.getWorkspace().getRoot().getProject(C_PROJECT_NAME);
    fCProjectFolder = cProject.getLocation().toFile();
}
 
Example 16
/**
 * Things to setup
 */
@BeforeClass
public static void beforeClass() {

    SWTBotUtils.initialize();
    Thread.currentThread().setName("SWTBotTest");
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

}
 
Example 17
Source Project: commons-configuration   Source File: TestExprLookup.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLookup() throws Exception
{
    final ConsoleAppender app = new ConsoleAppender(new SimpleLayout());
    final Log log = LogFactory.getLog("TestLogger");
    final Logger logger = ((Log4JLogger)log).getLogger();
    logger.addAppender(app);
    logger.setLevel(Level.DEBUG);
    logger.setAdditivity(false);
    final ExprLookup.Variables vars = new ExprLookup.Variables();
    vars.add(new ExprLookup.Variable("String", org.apache.commons.lang3.StringUtils.class));
    vars.add(new ExprLookup.Variable("Util", new Utility("Hello")));
    vars.add(new ExprLookup.Variable("System", "Class:java.lang.System"));
    final XMLConfiguration config = loadConfig();
    final ConfigurationLogger testLogger = new ConfigurationLogger("TestLogger");
    config.setLogger(testLogger);
    final ExprLookup lookup = new ExprLookup(vars);
    lookup.setInterpolator(config.getInterpolator());
    lookup.setLogger(testLogger);
    String str = lookup.lookup(PATTERN1);
    assertTrue(str.startsWith("Goodbye"));
    str = lookup.lookup(PATTERN2);
    assertTrue("Incorrect value: " + str, str.equals("value Some text"));
    logger.removeAppender(app);
}
 
Example 18
Source Project: tracecompass   Source File: FlameChartViewTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Initialization
 */
@BeforeClass
public static void init() {
    SWTBotUtils.initialize();

    Thread.currentThread().setName("SWTBot Thread"); // for the debugger
    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    sfLogger.removeAllAppenders();
    sfLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
    sfBot = new SWTWorkbenchBot();

    SWTBotUtils.closeView("Statistics", sfBot);
    /* finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 19
Source Project: tracecompass   Source File: FindDialogTestBase.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Before Class
 *
 * @throws IOException
 *             When the trace could not be opened
 */
@BeforeClass
public static void beforeClass() throws IOException {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.closeView("welcome", fBot);
    /* Switch perspectives */
    SWTBotUtils.switchToPerspective(KERNEL_PERSPECTIVE_ID);
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Open the trace */
    String tracePath = FileUtils.toFile(FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL())).getAbsolutePath();
    SWTBotUtils.openTrace(TRACE_PROJECT_NAME, tracePath, KERNEL_TRACE_TYPE);
    /* Finish waiting for eclipse to load */
    SWTBotUtils.activateEditor(fBot, CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL().getPath().replaceAll("/", ""));
}
 
Example 20
Source Project: tracecompass   Source File: KernelTestBase.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Before Class
 */
@BeforeClass
public static void beforeClass() {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.closeView("welcome", fBot);
    /* Switch perspectives */
    SWTBotUtils.switchToPerspective(KERNEL_PERSPECTIVE_ID);
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 21
/**
 * Before Class
 *
 * @throws IOException
 *             If the traces can not be found
 */
@BeforeClass
public static void beforeClass() throws IOException {
    SWTBotUtils.initialize();

    /* set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.closeView("welcome", fBot);
    /* Switch perspectives */
    SWTBotUtils.switchToPerspective(KERNEL_PERSPECTIVE_ID);
    /* Create the trace project */
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);
    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
}
 
Example 22
Source Project: cpsolver   Source File: Test.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Setup log4j logging
 * 
 * @param logFile  log file
 * @param debug true if debug messages should be logged (use -Ddebug=true to enable debug message)
 */
public static void setupLogging(File logFile, boolean debug) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
    if (!debug)
        root.setLevel(Level.INFO);
}
 
Example 23
Source Project: cpsolver   Source File: Test.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Setup log4j logging
 * 
 * @param logFile
 *            log file
 * @param debug
 *            true if debug messages should be logged (use -Ddebug=true to
 *            enable debug message)
 */
public static void setupLogging(File logFile, boolean debug) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout(
                    "%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
    if (!debug)
        root.setLevel(Level.INFO);
}
 
Example 24
Source Project: cpsolver   Source File: Test.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Setup log4j logging
 * 
 * @param logFile  log file
 */
public static void setupLogging(File logFile) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
}
 
Example 25
Source Project: render   Source File: LogUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void setupExecutorLog4j(final String context,
                                      final String rootLoggerName) {

    final Logger logger = LogManager.getLogger(rootLoggerName);

    for (final Enumeration e = LogManager.getRootLogger().getAllAppenders(); e.hasMoreElements(); ) {
        final Appender a = (Appender) e.nextElement();
        if (a instanceof ConsoleAppender) {
            final Layout layout = a.getLayout();
            if (layout instanceof PatternLayout) {
                final PatternLayout patternLayout = (PatternLayout) layout;
                final String conversionPattern = "%d{ISO8601} [%t] [%X{context}] %-5p [%c] %m%n";
                if (! conversionPattern.equals(patternLayout.getConversionPattern())) {
                    a.setLayout(new PatternLayout(conversionPattern));
                }
            }
        }
    }

    MDC.put("context", context);

    logger.setLevel(Level.DEBUG);
}
 
Example 26
Source Project: coming   Source File: PatternMatchingTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	ConsoleAppender console = new ConsoleAppender();
	String PATTERN = "%m%n";
	console.setLayout(new PatternLayout(PATTERN));
	console.setThreshold(Level.INFO);
	console.activateOptions();
	Logger.getRootLogger().getLoggerRepository().resetConfiguration();
	Logger.getRootLogger().addAppender(console);

	File s = getFile("patterns_examples/case1/1205753_EmbedPooledConnection_0_s.java");
	File t = getFile("patterns_examples/case1/1205753_EmbedPooledConnection_0_t.java");
	FineGrainDifftAnalyzer r = new FineGrainDifftAnalyzer();
	diffUpdate = r.getDiff(s, t);
	System.out.println("Output: " + diffUpdate);
	Assert.assertEquals(1, diffUpdate.getRootOperations().size());

	s = getFile("patterns_examples/case2/1205753_EmbedPooledConnection_0_s.java");
	t = getFile("patterns_examples/case2/1205753_EmbedPooledConnection_0_t.java");
	diffInsert = r.getDiff(s, t);
	System.out.println("Output: " + diffInsert);
	Assert.assertEquals(1, diffInsert.getRootOperations().size());

}
 
Example 27
Source Project: olat   Source File: Log4JInitServlet.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
    String file = getInitParameter("log4j-init-file");
    ClassPathResource res = new ClassPathResource(file);
    if (!res.exists()) {
        // creating basic log4j configuration which writes to console out, Only called when not yet configured
        ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"), ConsoleAppender.SYSTEM_OUT);
        appender.setThreshold(Level.INFO);
        BasicConfigurator.configure(appender);

        log.info("*****************************************************************************************");
        log.info("You don't provide a log4j config file for your OLAT instance. OLAT will just log to standard out (e.g. catalina.out)."
                + " Please provide a proper log config file (log4j.xml, see olat/conf for an example or read the installation guide) "
                + "and place it into the root of the classpath e.g. tomcat/lib or WEB-INF/classes");
        log.info("*****************************************************************************************");
    }
}
 
Example 28
Source Project: datafu   Source File: PigTests.java    License: Apache License 2.0 5 votes vote down vote up
@org.testng.annotations.BeforeClass
public void beforeClass()
{
  Logger.getRootLogger().removeAllAppenders();
  Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
  Logger.getRootLogger().setLevel(Level.INFO);
  Logger.getLogger(JvmMetrics.class).setLevel(Level.OFF);

  System.setProperty("pig.import.search.path", System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator + "resources");

  // Test files will be created in the following sub-directory
  new File(System.getProperty("user.dir") + File.separator + "build", "test-files").mkdir();
}
 
Example 29
private static void enableLogging() {
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%p [%c{1}] %m%n")));
    log.setLevel(Level.TRACE);
    Logger.getLogger(ColumnBasedHandlerTestUtil.class).setLevel(Level.TRACE);
    Logger.getLogger(ContentIndexingColumnBasedHandler.class).setLevel(Level.TRACE);
    Logger.getLogger(ContentBaseIngestHelper.class).setLevel(Level.TRACE);
}
 
Example 30
private static void enableLogging() {
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%p [%c{1}] %m%n")));
    log.setLevel(Level.TRACE);
    Logger.getLogger(ColumnBasedHandlerTestUtil.class).setLevel(Level.TRACE);
    Logger.getLogger(ContentIndexingColumnBasedHandler.class).setLevel(Level.TRACE);
    Logger.getLogger(ContentBaseIngestHelper.class).setLevel(Level.TRACE);
}