use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.
the class CsvJsonParameterLayoutFileAppenderTest method testNoNulCharacters.
public void testNoNulCharacters(final String message, final String expected) throws IOException {
@SuppressWarnings("resource") final LoggerContext loggerContext = loggerContextRule.getLoggerContext();
final Logger logger = loggerContext.getLogger("com.example");
logger.error("log:", message);
loggerContext.stop();
final File file = new File(FILE_PATH);
final byte[] contents = Files.toByteArray(file);
int count0s = 0;
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < contents.length; i++) {
final byte b = contents[i];
if (b == 0) {
sb.append(i);
sb.append(", ");
count0s++;
}
}
Assert.assertEquals("File contains " + count0s + " 0x00 byte at indices " + sb, 0, count0s);
final List<String> readLines = Files.readLines(file, Charset.defaultCharset());
final String actual = readLines.get(0);
// Assert.assertTrue(actual, actual.contains(message));
Assert.assertEquals(actual, expected, actual);
Assert.assertEquals(1, readLines.size());
}
use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.
the class ScriptAppenderSelectorTest method logAndCheck.
private void logAndCheck() {
final Marker marker = MarkerManager.getMarker("HEXDUMP");
final Logger logger = loggerContextRule.getLogger(ScriptAppenderSelectorTest.class);
logger.error("Hello");
final ListAppender listAppender = getListAppender();
final List<LogEvent> list = listAppender.getEvents();
assertNotNull("No events generated", list);
assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
logger.error("World");
assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
logger.error(marker, "DEADBEEF");
assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.
the class CsvParameterLayoutTest method testLayoutDefaultObjectArrayMessage.
@Test
public void testLayoutDefaultObjectArrayMessage() throws Exception {
final Logger root = this.init.getRootLogger();
testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), true);
}
use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.
the class CsvParameterLayoutTest method testLayoutDefaultNormal.
@Test
public void testLayoutDefaultNormal() throws Exception {
final Logger root = this.init.getRootLogger();
testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
}
use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.
the class CsvParameterLayoutTest method testLayoutTab.
@Test
public void testLayoutTab() throws Exception {
final Logger root = this.init.getRootLogger();
testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
}
Aggregations