Java Code Examples for org.apache.log4j.Logger#setAdditivity()
The following examples show how to use
org.apache.log4j.Logger#setAdditivity() .
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: LoggerBuilder.java From jforgame with Apache License 2.0 | 7 votes |
private static Logger build(String name) { Logger logger = Logger.getLogger(name); logger.removeAllAppenders(); logger.setLevel(Level.INFO); logger.setAdditivity(false); RollingFileAppender appender = new RollingFileAppender(); PatternLayout layout = new PatternLayout(); String conversionPatten = "[%d] %p %t %c - %m%n"; layout.setConversionPattern(conversionPatten); appender.setLayout(layout); appender.setEncoding("utf-8"); appender.setAppend(true); TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy(); String fp = LoggerBuilder.LOG_PATH + name + "/" + name + ".log.%d{yyyy-MM-dd}"; policy.setFileNamePattern(fp); appender.setRollingPolicy(policy); appender.activateOptions(); logger.addAppender(appender); container.put(name,logger); return logger; }
Example 2
Source File: TestExprLookup.java From commons-configuration with Apache License 2.0 | 6 votes |
@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 3
Source File: JackrabbitMain.java From commons-vfs with Apache License 2.0 | 6 votes |
private void prepareServerLog(final File log) throws IOException { final Layout layout = new PatternLayout("%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m%n"); final Logger jackrabbitLog = Logger.getRootLogger(); jackrabbitAppender = new FileAppender(layout, new File(log, "jackrabbit.log").getPath()); jackrabbitAppender.setThreshold(Level.ALL); jackrabbitLog.addAppender(jackrabbitAppender); final Logger jettyLog = Logger.getLogger("org.mortbay.log"); jettyAppender = new FileAppender(layout, new File(log, "jetty.log").getPath()); jettyAppender.setThreshold(Level.ALL); jettyLog.addAppender(jettyAppender); jettyLog.setAdditivity(false); System.setProperty("derby.stream.error.file", new File(log, "derby.log").getPath()); }
Example 4
Source File: LogUtil.java From datacollector with Apache License 2.0 | 6 votes |
public static boolean registerLogger(String pipelineName, String rev, String suffix, String filename, Configuration configuration) { String loggerName = getLoggerName(pipelineName, rev, suffix); boolean registered; Logger logger = Logger.getLogger(loggerName); if (logger.getAppender(loggerName) != null) { LOG.debug("Logger '{}' already exists", loggerName); registered = false; } else { synchronized (logger) { if (logger.getAppender(loggerName) == null) { logger.setAdditivity(false); logger.addAppender(createRollingFileAppender(loggerName, filename, configuration)); registered = true; } else { LOG.debug("Logger '{}' already exists", loggerName); registered = false; } } } return registered; }
Example 5
Source File: TaskLogger.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
private Logger createLog4jLogger(TaskId taskId) { LogLog.setQuietMode(true); // error about log should not be logged Logger tempLogger = Logger.getLogger(Log4JTaskLogs.JOB_LOGGER_PREFIX + taskId.getJobId() + "." + taskId.value()); tempLogger.setLevel(Log4JTaskLogs.STDOUT_LEVEL); tempLogger.setAdditivity(false); resetLogContextForImmediateService(); tempLogger.removeAllAppenders(); taskLogAppender = new AsyncAppenderWithStorage(getLogMaxSize(taskId)); tempLogger.addAppender(taskLogAppender); return tempLogger; }
Example 6
Source File: TestContainerLogAppender.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testAppendInClose() throws Exception { final ContainerLogAppender claAppender = new ContainerLogAppender(); claAppender.setName("testCLA"); claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n")); claAppender.setContainerLogDir("target/testAppendInClose/logDir"); claAppender.setContainerLogFile("syslog"); claAppender.setTotalLogFileSize(1000); claAppender.activateOptions(); final Logger claLog = Logger.getLogger("testAppendInClose-catergory"); claLog.setAdditivity(false); claLog.addAppender(claAppender); claLog.info(new Object() { public String toString() { claLog.info("message1"); return "return message1"; } }); claAppender.close(); }
Example 7
Source File: TestContainerLogAppender.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testAppendInClose() throws Exception { final ContainerLogAppender claAppender = new ContainerLogAppender(); claAppender.setName("testCLA"); claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n")); claAppender.setContainerLogDir("target/testAppendInClose/logDir"); claAppender.setContainerLogFile("syslog"); claAppender.setTotalLogFileSize(1000); claAppender.activateOptions(); final Logger claLog = Logger.getLogger("testAppendInClose-catergory"); claLog.setAdditivity(false); claLog.addAppender(claAppender); claLog.info(new Object() { public String toString() { claLog.info("message1"); return "return message1"; } }); claAppender.close(); }
Example 8
Source File: MavenLog4JConfigurator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void configureLog4j(Log log, String name) { Logger logger = Logger.getLogger(name); logger.setAdditivity(false); try { logger.setLevel(LOG4J_DEFAULT_LOG_LEVEL); } catch (NoSuchMethodError e) { // see http://bugzilla.slf4j.org/show_bug.cgi?id=279 } logger.removeAllAppenders(); logger.addAppender(createMojoLogAppender(log)); }
Example 9
Source File: N4jsUiLoggingInitializer.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Initializes the log4j logging with an additional appender which routes the logging to the Eclipse ErrorView. */ public static void init() { Logger rootLogger = Logger.getRootLogger(); // # This appender will write to the Eclipse error log. It will ONLY log ERROR and FATAL messages. // log4j.appender.eclipse=org.eclipse.xtext.logging.EclipseLogAppender EclipseLogAppender eclipseAppender = new EclipseLogAppender(); eclipseAppender.setName("eclipse"); eclipseAppender.setThreshold(Level.ERROR); rootLogger.addAppender(eclipseAppender); // log4j.appender.eclipse.layout=org.apache.log4j.PatternLayout // log4j.appender.eclipse.layout.ConversionPattern=%c %x - %m%n eclipseAppender.setLayout(new PatternLayout("%c %x - %m%n")); // # EclipseLogAppender must not log to the 'eclipse' appender as that would cause a stack overflow! // log4j.additivity.org.eclipse.xtext.logging.EclipseLogAppender=false // log4j.logger.org.eclipse.xtext.logging.EclipseLogAppender=WARN, default Logger eclipseAppenderLogger = Logger.getLogger(EclipseLogAppender.class); eclipseAppenderLogger.setAdditivity(false); eclipseAppenderLogger.setLevel(Level.WARN); Appender defaultAppender = eclipseAppenderLogger.getAppender("default"); if (eclipseAppenderLogger.getAllAppenders().hasMoreElements()) { eclipseAppenderLogger.removeAllAppenders(); } if (defaultAppender != null) { eclipseAppenderLogger.addAppender(defaultAppender); } }
Example 10
Source File: RunForestTransformer.java From UDepLambda with Apache License 2.0 | 4 votes |
@Override public void run(OptionSet options) { try { int nthreadsVal = options.valueOf(nthreads); String inputFileVal = options.valueOf(inputFile); InputStream inputStream = SentenceUtils.getInputStream(inputFileVal); MutableTypeRepository types = new MutableTypeRepository(options.valueOf(definedTypesFile)); LogicLanguageServices.setInstance(new LogicLanguageServices.Builder( types, new FlexibleTypeComparator()).closeOntology(false) .setNumeralTypeName("i").build()); TransformationRuleGroups treeTransformationRules = new TransformationRuleGroups(options.valueOf(treeTransformationsFile)); TransformationRuleGroups relationPrioritiesRules = new TransformationRuleGroups(options.valueOf(relationPrioritiesFile)); TransformationRuleGroups lambdaAssignmentRules = new TransformationRuleGroups( options.valueOf(lambdaAssignmentRulesFile)); Logger logger = null; if (!options.valueOf(debugToFile).equals("")) { logger = Logger.getLogger(getClass()); PatternLayout layout = new PatternLayout("%r [%t] %-5p: %m%n"); logger.setLevel(Level.DEBUG); logger.setAdditivity(false); Appender fileAppender = new FileAppender(layout, options.valueOf(debugToFile)); logger.addAppender(fileAppender); } TreeTransformerMain treeTransformer = new TreeTransformerMain(treeTransformationRules, relationPrioritiesRules, lambdaAssignmentRules, logger, options.valueOf(lexicalizePredicates)); if (options.valueOf(inputTypeIsForest)) { ForestTransformerMain forestTransoformer = new ForestTransformerMain(treeTransformer); forestTransoformer.processStream(inputStream, System.out, nthreadsVal, true); } else { treeTransformer.processStream(inputStream, System.out, nthreadsVal, true); } } catch (IOException | InterruptedException e) { e.printStackTrace(); } }
Example 11
Source File: LogInitializer.java From zipkin-dependencies with Apache License 2.0 | 4 votes |
static void addLogAppendersFromRoot(Logger zipkinLogger) { zipkinLogger.setAdditivity(false); for (Enumeration e = Logger.getRootLogger().getAllAppenders(); e.hasMoreElements(); ) { zipkinLogger.addAppender((Appender) e.nextElement()); } }
Example 12
Source File: NlpPipeline.java From UDepLambda with Apache License 2.0 | 4 votes |
public NlpPipeline(Map<String, String> options) throws Exception { super(options); System.err.println(options); this.options = options; if (options.containsKey(DEPLAMBDA) && options.get(DEPLAMBDA).equals("true")) { System.err.println("Loading DepLambda Model.. "); try { MutableTypeRepository types = new MutableTypeRepository(options.get(DEPLAMBDA_DEFINED_TYPES_FILE)); System.err.println(String.format("%s=%s", DEPLAMBDA_DEFINED_TYPES_FILE, options.get(DEPLAMBDA_DEFINED_TYPES_FILE))); LogicLanguageServices.setInstance(new LogicLanguageServices.Builder( types, new FlexibleTypeComparator()).closeOntology(false) .setNumeralTypeName("i").build()); TransformationRuleGroups treeTransformationRules; treeTransformationRules = new TransformationRuleGroups( options.get(DEPLAMBDA_TREE_TRANSFORMATIONS_FILE)); System.err.println(String.format("%s=%s", DEPLAMBDA_TREE_TRANSFORMATIONS_FILE, options.get(DEPLAMBDA_TREE_TRANSFORMATIONS_FILE))); TransformationRuleGroups relationPrioritiesRules = new TransformationRuleGroups( options.get(DEPLAMBDA_RELATION_PRORITIES_FILE)); System.err.println(String.format("%s=%s", DEPLAMBDA_RELATION_PRORITIES_FILE, options.get(DEPLAMBDA_RELATION_PRORITIES_FILE))); TransformationRuleGroups lambdaAssignmentRules = new TransformationRuleGroups( options.get(DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE)); System.err.println(String.format("%s=%s", DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE, options.get(DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE))); Boolean lexicalizePredicates = Boolean.parseBoolean(options.getOrDefault( DEPLAMBDA_LEXICALIZE_PREDICATES, "true")); Logger logger = null; if (options.containsKey(DEPLAMBDA_DEBUG_TO_FILE) && !options.get(DEPLAMBDA_DEBUG_TO_FILE).trim().equals("")) { logger = Logger.getLogger(getClass()); PatternLayout layout = new PatternLayout("%r [%t] %-5p: %m%n"); logger.setLevel(Level.DEBUG); logger.setAdditivity(false); Appender fileAppender = new FileAppender(layout, options.get(DEPLAMBDA_DEBUG_TO_FILE)); logger.addAppender(fileAppender); } treeTransformer = new TreeTransformerMain(treeTransformationRules, relationPrioritiesRules, lambdaAssignmentRules, logger, lexicalizePredicates); System.err.println("Loaded DepLambda Model.. "); } catch (IOException e) { e.printStackTrace(); } } }
Example 13
Source File: LogInitializer.java From zipkin-sparkstreaming with Apache License 2.0 | 4 votes |
static void addLogAppendersFromRoot(Logger zipkinLogger) { zipkinLogger.setAdditivity(false); for (Enumeration e = Logger.getRootLogger().getAllAppenders(); e.hasMoreElements(); ) { zipkinLogger.addAppender((Appender) e.nextElement()); } }
Example 14
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 15
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 16
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 17
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 18
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 19
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)); }