Java Code Examples for org.apache.log4j.Logger#getAdditivity()
The following examples show how to use
org.apache.log4j.Logger#getAdditivity() .
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: LogInitializer.java From zipkin-sparkstreaming with Apache License 2.0 | 5 votes |
@Override public void run() { Logger zipkinLogger = LogManager.getLogger("zipkin"); if (!log4Jlevel().equals(zipkinLogger.getLevel())) { zipkinLogger.setLevel(log4Jlevel()); if (zipkinLogger.getAdditivity()) { addLogAppendersFromRoot(zipkinLogger); } } java.util.logging.Logger.getLogger("zipkin").setLevel(julLevel()); }
Example 2
Source File: LogInitializer.java From zipkin-dependencies with Apache License 2.0 | 5 votes |
@Override public void run() { Logger zipkinLogger = LogManager.getLogger("zipkin2"); if (!log4Jlevel.equals(zipkinLogger.getLevel())) { zipkinLogger.setLevel(log4Jlevel); if (zipkinLogger.getAdditivity()) { addLogAppendersFromRoot(zipkinLogger); } } java.util.logging.Logger.getLogger("zipkin2").setLevel(julLevel); }
Example 3
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testCollisionLogging() throws Exception { Logger logger = Logger.getLogger("fluo.tx.collisions"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%p, %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (LoaderExecutor le = client.newLoaderExecutor()) { for (int i = 0; i < 20; i++) { le.execute(new SimpleBinaryLoader()); le.execute(new TriggerLoader(i)); } } miniFluo.waitForObservers(); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } String logMsgs = writer.toString(); logMsgs = logMsgs.replace('\n', ' '); Assert.assertFalse(logMsgs.contains("TriggerLoader")); String pattern; pattern = ".*txid: (\\d+) class: org.apache.fluo.integration.log.LogIT\\$SimpleBinaryLoader"; pattern += ".*txid: \\1 collisions: \\Q[r1\\x0d=[a \\x00\\x09 ]]\\E.*"; Assert.assertTrue(logMsgs.matches(pattern)); pattern = ".*txid: (\\d+) trigger: \\d+ stat count \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$TestObserver"; pattern += ".*txid: \\1 collisions: \\Q[all=[stat count ]]\\E.*"; Assert.assertTrue(logMsgs.matches(pattern)); }
Example 4
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testSummaryLogging() throws Exception { Logger logger = Logger.getLogger("fluo.tx.summary"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%p, %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (LoaderExecutor le = client.newLoaderExecutor()) { for (int i = 0; i < 20; i++) { le.execute(new SimpleLoader()); le.execute(new TriggerLoader(i)); } } miniFluo.waitForObservers(); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } String logMsgs = writer.toString(); logMsgs = logMsgs.replace('\n', ' '); Assert.assertTrue(logMsgs.matches(".*txid: \\d+ thread : \\d+ " + "time: \\d+ \\(\\d+ \\d+\\) #ret: 0 #set: 1 #collisions: 0 waitTime: \\d+ " + "committed: true class: TriggerLoader.*")); Assert.assertTrue(logMsgs.matches(".*txid: \\d+ thread : \\d+ " + "time: \\d+ \\(\\d+ \\d+\\) #ret: 1 #set: 1 #collisions: 0 waitTime: \\d+ " + "committed: true class: SimpleLoader.*")); Assert.assertTrue(logMsgs.matches(".*txid: \\d+ thread : \\d+ " + "time: \\d+ \\(\\d+ \\d+\\) #ret: 1 #set: 1 #collisions: 1 waitTime: \\d+ " + "committed: false class: SimpleLoader.*")); Assert.assertTrue(logMsgs.matches(".*txid: \\d+ thread : \\d+ " + "time: \\d+ \\(\\d+ \\d+\\) #ret: 2 #set: 1 #collisions: 0 waitTime: \\d+ " + "committed: true class: TestObserver.*")); Assert.assertTrue(logMsgs.matches(".*txid: \\d+ thread : \\d+ " + "time: \\d+ \\(\\d+ \\d+\\) #ret: 2 #set: 1 #collisions: 1 waitTime: \\d+ " + "committed: false class: TestObserver.*")); }
Example 5
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testAllLogging() throws Exception { Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (LoaderExecutor le = client.newLoaderExecutor()) { le.execute(new SimpleLoader()); } try (LoaderExecutor le = client.newLoaderExecutor()) { le.execute(new TriggerLoader(0)); } miniFluo.waitForObservers(); try (Snapshot snap = client.newSnapshot()) { Assert.assertTrue(Integer.parseInt(snap.gets("all", STAT_COUNT)) >= 1); Assert.assertEquals("1", snap.gets("r1", new Column("a", "b"))); } String logMsgs = writer.toString(); logMsgs = logMsgs.replace('\n', ' '); String pattern; // simple loader should cause this pattern in logs pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$SimpleLoader"; pattern += ".*txid: \\1 get\\(r1, a b \\) -> null"; pattern += ".*txid: \\1 set\\(r1, a b , 1\\)"; pattern += ".*txid: \\1 commit\\(\\) -> SUCCESSFUL commitTs: \\d+"; pattern += ".*"; Assert.assertTrue(logMsgs.matches(pattern)); waitForClose(writer, pattern); // trigger loader should cause this pattern in logs pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$TriggerLoader"; pattern += ".*txid: \\1 set\\(0, stat count , 1\\)"; pattern += ".*txid: \\1 setWeakNotification\\(0, stat count \\)"; pattern += ".*txid: \\1 commit\\(\\) -> SUCCESSFUL commitTs: \\d+"; pattern += ".*"; Assert.assertTrue(logMsgs.matches(pattern)); waitForClose(writer, pattern); // observer should cause this pattern in logs pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 trigger: 0 stat count \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$TestObserver"; pattern += ".*txid: \\1 get\\(0, stat count \\) -> 1"; pattern += ".*txid: \\1 get\\(all, stat count \\) -> null"; pattern += ".*txid: \\1 set\\(all, stat count , 1\\)"; pattern += ".*txid: \\1 commit\\(\\) -> SUCCESSFUL commitTs: \\d+"; pattern += ".*"; Assert.assertTrue(logMsgs.matches(pattern)); waitForClose(writer, pattern); // two gets done by snapshot should cause this pattern pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 get\\(all, stat count \\) -> 1"; pattern += ".*txid: \\1 get\\(r1, a b \\) -> 1"; pattern += ".*txid: \\1 close\\(\\).*"; Assert.assertTrue(logMsgs.matches(pattern)); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } }
Example 6
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testGetMethods() { Column c1 = new Column("f1", "q1"); Column c2 = new Column("f1", "q2"); try (Transaction tx = client.newTransaction()) { tx.set("r1", c1, "v1"); tx.set("r1", c2, "v2"); tx.set("r2", c1, "v3"); tx.set("r2", c2, "v4"); tx.commit(); } Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (Snapshot snap = client.newSnapshot()) { Map<RowColumn, String> ret1 = snap.gets(Arrays.asList(new RowColumn("r1", c1), new RowColumn("r2", c2))); Assert.assertEquals( ImmutableMap.of(new RowColumn("r1", c1), "v1", new RowColumn("r2", c2), "v4"), ret1); Map<String, Map<Column, String>> ret2 = snap.gets(Arrays.asList("r1", "r2"), ImmutableSet.of(c1)); Assert.assertEquals( ImmutableMap.of("r1", ImmutableMap.of(c1, "v1"), "r2", ImmutableMap.of(c1, "v3")), ret2); Map<Column, String> ret3 = snap.gets("r1", ImmutableSet.of(c1, c2)); Assert.assertEquals(ImmutableMap.of(c1, "v1", c2, "v2"), ret3); Assert.assertEquals("v1", snap.gets("r1", c1)); } miniFluo.waitForObservers(); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } String pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 \\Qget([r1 f1 q1 , r2 f1 q2 ]) -> [r2 f1 q2 =v4, r1 f1 q1 =v1]\\E"; pattern += ".*txid: \\1 \\Qget([r1, r2], [f1 q1 ]) -> [r1=[f1 q1 =v1], r2=[f1 q1 =v3]]\\E"; pattern += ".*txid: \\1 \\Qget(r1, [f1 q1 , f1 q2 ]) -> [f1 q1 =v1, f1 q2 =v2]\\E"; pattern += ".*txid: \\1 \\Qget(r1, f1 q1 ) -> v1\\E"; pattern += ".*txid: \\1 close\\(\\).*"; String origLogMsgs = writer.toString(); String logMsgs = origLogMsgs.replace('\n', ' '); Assert.assertTrue(logMsgs.matches(pattern)); }
Example 7
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testBinaryLogging() throws Exception { Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (LoaderExecutor le = client.newLoaderExecutor()) { le.execute(new BinaryLoader1()); } miniFluo.waitForObservers(); String pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$BinaryLoader1"; pattern += ".*txid: \\1 \\Qdelete(r\\x051, c\\x021 c\\xf51 )\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, c\\x021 c\\xf51 ) -> null\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> []\\E"; pattern += ".*txid: \\1 \\Qget([r\\x051, r\\x062], [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> []\\E"; pattern += ".*txid: \\1 \\Qset(r\\x051, c\\x092 c\\xe52 , v\\x992)\\E"; pattern += ".*txid: \\1 \\Qset(r\\x062, c\\x092 c\\xe52 , v\\xd91)\\E"; pattern += ".*txid: \\1 \\QsetWeakNotification(r\\x062, c\\x092 c\\xe52 )\\E"; pattern += ".*txid: \\1 \\Qcommit()\\E -> SUCCESSFUL commitTs: \\d+"; pattern += ".*"; String origLogMsgs = writer.toString(); String logMsgs = origLogMsgs.replace('\n', ' '); Assert.assertTrue(origLogMsgs, logMsgs.matches(pattern)); waitForClose(writer, pattern); final String v1 = "\\Qr\\x051=[c\\x092 c\\xe52 =v\\x992]\\E"; final String v2 = "\\Qr\\x062=[c\\x092 c\\xe52 =v\\xd91]\\E"; pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 \\Qtrigger: r\\x062 c\\x092 c\\xe52 4\\E"; pattern += ".*txid: \\1 \\Qclass: org.apache.fluo.integration.log.LogIT$BinaryObserver\\E"; pattern += ".*txid: \\1 \\Qget(r\\x051, c\\x092 c\\xe52 ) -> v\\x992\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> " + "[c\\x092 c\\xe52 =v\\xd91]\\E"; pattern += ".*txid: \\1 \\Qget([r\\x051, r\\x062], [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> " + "[\\E(" + v1 + "|" + v2 + ")\\, (" + v1 + "|" + v2 + ")\\]"; pattern += ".*txid: \\1 \\Qcommit() -> SUCCESSFUL commitTs: -1\\E"; pattern += ".*"; Assert.assertTrue(origLogMsgs, logMsgs.matches(pattern)); waitForClose(writer, pattern); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } }
Example 8
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testReadLocks() { Column c1 = new Column("f1", "q1"); Column c2 = new Column("f1", "q2"); try (Transaction tx = client.newTransaction()) { tx.set("r1", c1, "v1"); tx.set("r1", c2, "v2"); tx.set("r2", c1, "v3"); tx.set("r2", c2, "v4"); tx.commit(); } Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (Transaction tx = client.newTransaction()) { Assert.assertEquals("v1", tx.withReadLock().gets("r1", c1)); Assert.assertEquals(ImmutableMap.of(c1, "v3", c2, "v4"), tx.withReadLock().gets("r2", c1, c2)); Assert.assertEquals(ImmutableMap.of(new RowColumn("r1", c2), "v2"), tx.withReadLock().gets(Arrays.asList(new RowColumn("r1", c2)))); Map<String, Map<Column, String>> expected = new HashMap<>(); expected.computeIfAbsent("r1", k -> new HashMap<>()).put(c1, "v1"); expected.computeIfAbsent("r2", k -> new HashMap<>()).put(c1, "v3"); Map<String, Map<Column, String>> actual = tx.withReadLock().gets(Arrays.asList("r1", "r2"), ImmutableSet.of(c1)); Assert.assertEquals(expected, actual); tx.set("r3", c1, "345"); tx.commit(); } } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } String pattern = ""; pattern += ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 \\QwithReadLock().get(r1, f1 q1 ) -> v1\\E"; pattern += ".*txid: \\1 \\QwithReadLock().get(r2, [f1 q1 , f1 q2 ]) -> [f1 q1 =v3, f1 q2 =v4]\\E"; pattern += ".*txid: \\1 \\QwithReadLock().get([r1 f1 q2 ]) -> [r1 f1 q2 =v2]\\E"; pattern += ".*txid: \\1 \\QwithReadLock().get([r1, r2], [f1 q1 ]) -> " + "[r1=[f1 q1 =v1], r2=[f1 q1 =v3]]\\E"; pattern += ".*txid: \\1 \\Qset(r3, f1 q1 , 345)\\E"; pattern += ".*txid: \\1 \\Qcommit()\\E -> SUCCESSFUL commitTs: \\d+"; pattern += ".*txid: \\1 \\Qclose()\\E.*"; String origLogMsgs = writer.toString(); String logMsgs = origLogMsgs.replace('\n', ' '); Assert.assertTrue(origLogMsgs, logMsgs.matches(pattern)); }