use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ThresholdFilterTest method testThresholds.
@Test
public void testThresholds() {
final ThresholdFilter filter = ThresholdFilter.createFilter(Level.ERROR, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null, (Object) null, (Throwable) null));
assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));
LogEvent event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("Test")).build();
assertSame(Filter.Result.DENY, filter.filter(event));
event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.ERROR).setMessage(//
new SimpleMessage("Test")).build();
assertSame(Filter.Result.NEUTRAL, filter.filter(event));
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class RegexFilterTest method testThresholds.
@Test
public void testThresholds() throws Exception {
RegexFilter filter = RegexFilter.createFilter(".* test .*", null, false, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.DEBUG, null, (Object) "This is a test message", (Throwable) null));
assertSame(Filter.Result.DENY, filter.filter(null, Level.ERROR, null, (Object) "This is not a test", (Throwable) null));
LogEvent event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("Another test message")).build();
assertSame(Filter.Result.NEUTRAL, filter.filter(event));
event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.ERROR).setMessage(//
new SimpleMessage("test")).build();
assertSame(Filter.Result.DENY, filter.filter(event));
filter = RegexFilter.createFilter(null, null, false, null, null);
assertNull(filter);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class MutableLogEventTest method testJavaIoSerializableWithThrown.
@Test
public void testJavaIoSerializableWithThrown() throws Exception {
final MutableLogEvent evt = new MutableLogEvent();
evt.setContextData(CONTEXT_DATA);
evt.setContextStack(STACK);
evt.setEndOfBatch(true);
evt.setIncludeLocation(true);
evt.setLevel(Level.WARN);
evt.setLoggerFqcn(getClass().getName());
evt.setLoggerName("loggername");
evt.setMarker(MarkerManager.getMarker("marked man"));
// evt.setMessage(new ParameterizedMessage("message in a {}", "bottle")); // TODO ParameterizedMessage serialization
evt.setMessage(new SimpleMessage("peace for all"));
evt.setNanoTime(1234);
evt.setThreadId(987);
evt.setThreadName("ito");
evt.setThreadPriority(9);
evt.setThrown(new Exception());
evt.setTimeMillis(56789);
final byte[] binary = serialize(evt);
final Log4jLogEvent evt2 = deserialize(binary);
assertEquals(evt.getTimeMillis(), evt2.getTimeMillis());
assertEquals(evt.getLoggerFqcn(), evt2.getLoggerFqcn());
assertEquals(evt.getLevel(), evt2.getLevel());
assertEquals(evt.getLoggerName(), evt2.getLoggerName());
assertEquals(evt.getMarker(), evt2.getMarker());
assertEquals(evt.getContextData(), evt2.getContextData());
assertEquals(evt.getContextStack(), evt2.getContextStack());
assertEquals(evt.getMessage(), evt2.getMessage());
assertNotNull(evt2.getSource());
assertEquals(evt.getSource(), evt2.getSource());
assertEquals(evt.getThreadName(), evt2.getThreadName());
assertNull(evt2.getThrown());
assertNotNull(evt2.getThrownProxy());
assertEquals(evt.getThrownProxy(), evt2.getThrownProxy());
assertEquals(evt.isEndOfBatch(), evt2.isEndOfBatch());
assertEquals(evt.isIncludeLocation(), evt2.isIncludeLocation());
// nano time is transient in log4j log event
assertNotEquals(evt.getNanoTime(), evt2.getNanoTime());
assertEquals(0, evt2.getNanoTime());
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class LevelRangeFilterTest method testLevels.
@Test
public void testLevels() {
final LevelRangeFilter filter = LevelRangeFilter.createFilter(Level.ERROR, Level.INFO, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null, (Object) null, (Throwable) null));
assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));
LogEvent event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("Test")).build();
assertSame(Filter.Result.DENY, filter.filter(event));
event = //
Log4jLogEvent.newBuilder().setLevel(//
Level.ERROR).setMessage(//
new SimpleMessage("Test")).build();
assertSame(Filter.Result.NEUTRAL, filter.filter(event));
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class MarkerFilterTest method testMarkers.
@Test
public void testMarkers() {
final Marker parent = MarkerManager.getMarker("Parent");
final Marker child = MarkerManager.getMarker("Child").setParents(parent);
final Marker grandChild = MarkerManager.getMarker("GrandChild").setParents(child);
final Marker sibling = MarkerManager.getMarker("Sibling").setParents(parent);
final Marker stranger = MarkerManager.getMarker("Stranger");
MarkerFilter filter = MarkerFilter.createFilter("Parent", null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, null, stranger, (Object) null, (Throwable) null));
assertSame(Filter.Result.NEUTRAL, filter.filter(null, null, child, (Object) null, (Throwable) null));
assertSame(Filter.Result.NEUTRAL, filter.filter(null, null, grandChild, (Object) null, (Throwable) null));
filter.stop();
LogEvent event = //
Log4jLogEvent.newBuilder().setMarker(//
grandChild).setLevel(//
Level.DEBUG).setMessage(new SimpleMessage("Hello, world!")).build();
assertSame(Filter.Result.NEUTRAL, filter.filter(event));
filter = MarkerFilter.createFilter("Child", null, null);
filter.start();
assertSame(Filter.Result.NEUTRAL, filter.filter(event));
event = //
Log4jLogEvent.newBuilder().setMarker(//
sibling).setLevel(//
Level.DEBUG).setMessage(new SimpleMessage("Hello, world!")).build();
assertSame(Filter.Result.DENY, filter.filter(event));
filter.stop();
}
Aggregations