Permalink
Browse files

Make sure white spaces in log4j configuration does not affect async a…

…ppender configuration.
  • Loading branch information...
Karthik Ranganathan
Karthik Ranganathan committed Oct 14, 2013
1 parent f64549b commit c7563e85e4c5282ea6cda513444dd770a623598a
@@ -204,9 +204,10 @@ public void configure(Properties props) {
}
for (int i = 0; i < asyncAppenderArray.length; i++) {
String oneAppenderName = asyncAppenderArray[i];
- if (i == 0) {
+ if ((i == 0) || (oneAppenderName == null)) {
continue;
}
+ oneAppenderName = oneAppenderName.trim();
String oneAsyncAppenderName = oneAppenderName
+ ASYNC_APPENDERNAME_SUFFIX;
originalAsyncAppenderNameMap.put(oneAppenderName,
@@ -529,8 +530,11 @@ private void convertConfiguredAppendersToAsync(Properties props)
String valueString = "";
int ctr = 0;
for (String oneValue : values) {
+ if (oneValue == null) {
+ continue;
+ }
++ctr;
- if (originalAppenderName.equals(oneValue)) {
+ if (originalAppenderName.equals(oneValue.trim())) {
oneValue = asyncAppenderName;
}
if (ctr != values.length) {
@@ -148,6 +148,106 @@ public void run() {
}
+ @Test
+ public void testAsyncAppendersWithWhiteSpace() throws Exception {
+ props.setProperty("log4j.rootCategory", "OFF");
+ props.setProperty("log4j.logger.com.netflix.blitz4j.TestBlitz4j",
+ "INFO, stdout");
+ props.setProperty("log4j.logger.com.netflix.blitz4j.TestBlitz4j$1",
+ "INFO,stdout");
+ props.setProperty("log4j.appender.stdout",
+ "org.apache.log4j.ConsoleAppender");
+ props.setProperty("log4j.appender.stdout.layout",
+ "com.netflix.logging.log4jAdapter.NFPatternLayout");
+ props.setProperty("log4j.appender.stdout.layout.ConversionPattern",
+ "%d %-5p %C:%L [%t] [%M] %m%n");
+
+ props.setProperty("log4j.logger.asyncAppenders", "INFO,stdout");
+ props.setProperty(
+ "batcher.com.netflix.logging.AsyncAppender.stdout.waitTimeinMillis",
+ "120000");
+ LoggingConfiguration.getInstance().configure(props);
+ int noOfThreads = 100;
+ Thread[] tArray = new Thread[noOfThreads];
+ for (int i = 0; i < noOfThreads; i++) {
+ Thread t1 = new Thread(new Runnable() {
+
+ public void run() {
+ int i = 0;
+
+ while (i < 1000) {
+ i++;
+ Logger slflogger = LoggerFactory
+ .getLogger(TestBlitz4j.class);
+ slflogger.info("Testing named log with this string {}",
+ "Test String");
+ Thread.yield();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ });
+ tArray[i] = t1;
+ }
+
+ Thread t2 = new Thread(new Runnable() {
+
+ public void run() {
+ int i = 0;
+
+ while (i <= 1000) {
+ try {
+ ConfigurationManager.getConfigInstance().setProperty(
+ "log4j.junk", (i++) + "");
+ Thread.sleep(10);
+ // NetflixConfiguration.getInstance().setProperty("log4j.junk1",
+ // (i++) + "");
+ // Thread.sleep(10);
+ Thread.yield();
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ });
+ for (int i = 0; i < noOfThreads; i++) {
+ tArray[i].start();
+ }
+ t2.start();
+ t2.join();
+ for (int i = 0; i < noOfThreads; i++) {
+ tArray[i].join();
+ }
+
+ int numSummarizedConsole = 0;
+ try {
+ numSummarizedConsole = Integer
+ .valueOf(getMonitoringData(consoleSummarizeEvent));
+ } catch (Throwable e) {
+
+ }
+ int numAddedConsole = Integer
+ .valueOf(getMonitoringData(consoleEventsProcessed));
+ System.out
+ .println("The number of messages added to async batcher console: "
+ + numAddedConsole);
+ System.out
+ .println("The number of messages summarized from async batcher console : "
+ + numSummarizedConsole);
+ System.out.println("Total number of messages to asyncBatcher console: "
+ + (numAddedConsole + numSummarizedConsole));
+ Assert.assertTrue(((numAddedConsole + numSummarizedConsole) >= 100000));
+ LoggingConfiguration.getInstance().stop();
+
+ }
@Test
public void testReconfiguration() throws Exception {
Properties props = new Properties();

0 comments on commit c7563e8

Please sign in to comment.