Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-144] Allow a # to be used as an alternate for expressions in … #101

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static FormatStep[] getSteps(final String formatString, ColorMap colors)
timeZone = TimeZone.getTimeZone(argument);
break;
}
case '#':
case '$': {
stepList.add(Formatters.systemPropertyFormatStep(argument, leftJustify, minimumWidth, truncateBeginning, maximumWidth));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,8 @@ public void threads() throws Exception {

@Test
public void systemProperties() throws Exception {
final ExtLogRecord record = createLogRecord("test");
PatternFormatter formatter = new PatternFormatter("%${org.jboss.logmanager.testProp}");
Assert.assertEquals("testValue", formatter.format(record));

formatter = new PatternFormatter("%${invalid:defaultValue}");
Assert.assertEquals("defaultValue", formatter.format(record));

formatter = new PatternFormatter("%${invalid}");
Assert.assertEquals("null", formatter.format(record));

// Test null arguments
try {
formatter = new PatternFormatter("%$");
formatter.format(record);
Assert.fail("Should not allow null arguments");
} catch (IllegalArgumentException ignore) {

}

try {
formatter = new PatternFormatter("%${}");
formatter.format(record);
Assert.fail("Should not allow null arguments");
} catch (IllegalArgumentException ignore) {

}
systemProperties("$");
systemProperties("#");
}

@Test
Expand Down Expand Up @@ -249,6 +225,36 @@ public void extendedThrowable() throws Exception {
Assert.assertTrue(formatted.contains("CIRCULAR REFERENCE:java.lang.IllegalStateException: suppressedLevel1"));
}


private void systemProperties(final String propertyPrefix) throws Exception {
final ExtLogRecord record = createLogRecord("test");
PatternFormatter formatter = new PatternFormatter("%" + propertyPrefix + "{org.jboss.logmanager.testProp}");
Assert.assertEquals("testValue", formatter.format(record));

formatter = new PatternFormatter("%" + propertyPrefix + "{invalid:defaultValue}");
Assert.assertEquals("defaultValue", formatter.format(record));

formatter = new PatternFormatter("%" + propertyPrefix + "{invalid}");
Assert.assertEquals("null", formatter.format(record));

// Test null arguments
try {
formatter = new PatternFormatter("%" + propertyPrefix);
formatter.format(record);
Assert.fail("Should not allow null arguments");
} catch (IllegalArgumentException ignore) {

}

try {
formatter = new PatternFormatter("%" + propertyPrefix + "{}");
formatter.format(record);
Assert.fail("Should not allow null arguments");
} catch (IllegalArgumentException ignore) {

}
}

protected static ExtLogRecord createLogRecord(final String msg) {
final ExtLogRecord result = new ExtLogRecord(org.jboss.logmanager.Level.INFO, msg, PatternFormatterTests.class.getName());
result.setSourceClassName(PatternFormatterTests.class.getName());
Expand Down