Java Code Examples for org.apache.log4j.WriterAppender#activateOptions()
The following examples show how to use
org.apache.log4j.WriterAppender#activateOptions() .
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 File: FbLog4jTest.java From takes with MIT License | 5 votes |
/** * Helper method to set up stream. * @return ByteArrayOutputStream for logging */ private ByteArrayOutputStream setUpLoggerStream() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final WriterAppender appender = new WriterAppender( new SimpleLayout(), baos ); appender.setThreshold(Level.ERROR); appender.activateOptions(); Logger.getRootLogger().addAppender(appender); return baos; }
Example 2
Source File: NoKeyOnWireTest.java From GDH with MIT License | 4 votes |
private void testNegotiation(int amount, TestContext context) { PrimaryVertex pv = new PrimaryVertex(); GDHVertex[] verticles = new GDHVertex[amount]; Configuration[] confs = new Configuration[amount]; Writer writer = new StringWriter(); for (int i = 0; i < amount; i++) { verticles[i] = new GDHVertex(); confs[i] = new Configuration(); WriterAppender app = new WriterAppender(new PatternLayout(), writer); app.setThreshold(Level.DEBUG); app.activateOptions(); confs[i].setAppender(app); String port = amount + "08" + i; confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG); verticles[i].setConfiguration(confs[i]); } List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles)); Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList())); verticles[0].addGroup(g); Async async1 = context.async(amount); for (int i = 0; i < amount; i++) pv.run(verticles[i], res -> { if (res.succeeded()) { async1.countDown(); } else { res.cause().printStackTrace(); return; } }); async1.awaitSuccess(); BigInteger[] keys = new BigInteger[2]; try { keys[0] = verticles[0].exchange(g.getGroupId()).get(); Assert.assertFalse(!writer.toString().isEmpty() && writer.toString().contains(keys[0].toString())); } catch (InterruptedException | ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } Async async2 = context.async(amount); for (int i = 0; i < amount; i++) pv.kill(verticles[i], res -> { if (res.succeeded()) { async2.countDown(); } else { res.cause().printStackTrace(); } }); async2.awaitSuccess(); }
Example 3
Source File: LoggerTest.java From GDH with MIT License | 4 votes |
private void testNegotiation(int amount, TestContext context) { PrimaryVertex pv = new PrimaryVertex(); GDHVertex[] verticles = new GDHVertex[amount]; Configuration[] confs = new Configuration[amount]; Writer writer = new StringWriter(); for (int i = 0; i < amount; i++) { verticles[i] = new GDHVertex(); confs[i] = new Configuration(); WriterAppender app = new WriterAppender(new PatternLayout(), writer); app.setThreshold(Level.DEBUG); app.activateOptions(); confs[i].setAppender(app); String port = amount + "08" + i; confs[i].setIP("localhost").setPort(port).setLogLevel(Level.DEBUG); verticles[i].setConfiguration(confs[i]); } List<GDHVertex> list = new ArrayList<>(Arrays.asList(verticles)); Group g = new Group(confs[0], list.stream().map(y -> y.getNode()).collect(Collectors.toList())); verticles[0].addGroup(g); Async async1 = context.async(amount); for (int i = 0; i < amount; i++) pv.run(verticles[i], res -> { if (res.succeeded()) { async1.countDown(); } else { res.cause().printStackTrace(); return; } }); async1.awaitSuccess(); BigInteger[] keys = new BigInteger[1]; try { keys[0] = verticles[0].exchange(g.getGroupId()).get(); for (int j = 0; j < verticles.length; j++) { Assert.assertEquals(verticles[j].getKey(g.getGroupId()).get(), keys[0]); } String write = writer.toString(); int count1 = write.length() - write.replace(Constants.LOG_IN, "0000000").length(); int count2 = write.length() - write.replace(Constants.LOG_OUT, "0000000").length(); Assert.assertTrue(count1 >= amount*amount-1); Assert.assertTrue(count2 >= amount*amount-1); } catch (InterruptedException | ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } Async async2 = context.async(amount); for (int i = 0; i < amount; i++) pv.kill(verticles[i], res -> { if (res.succeeded()) { async2.countDown(); } else { res.cause().printStackTrace(); } }); async2.awaitSuccess(); }