Package org.apache.logging.log4j.message

Examples of org.apache.logging.log4j.message.MapMessage


                        newMap.put(entry.getKey(), entry.getValue());
                    }
                }
            }
        }
        final MapMessage message = ((MapMessage) msg).newInstance(newMap);
        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
            message, source.getThrown(), source.getContextMap(), source.getContextStack(), source.getThreadName(),
            source.getSource(), source.getMillis());
    }
View Full Code Here


        assertNotNull("No events generated", list);
        assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
        final LogEvent event = list.get(0);
        final Message m = event.getMessage();
        assertTrue("Message is not a MapMessage", m instanceof MapMessage);
        final MapMessage message = (MapMessage) m;
        final Map<String, String> map = message.getData();
        assertNotNull("No Map", map);
        assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size() == 3);
        final String value = map.get("Key1");
        assertEquals("Apache", value);
        app.clear();
View Full Code Here

    public void testFilter() {
        final KeyValuePair[] pairs = new KeyValuePair[] { new KeyValuePair("FromAccount", "211000"),
                                                    new KeyValuePair("ToAccount", "123456")};
        MapFilter filter = MapFilter.createFilter(pairs, "and", null, null);
        filter.start();
        MapMessage msg = new MapMessage();
        msg.put("ToAccount", "123456");
        msg.put("FromAccount", "211000");
        msg.put("Amount", "1000.00");
        assertTrue(filter.isStarted());
        assertTrue(filter.filter(null, Level.DEBUG, null, msg, null) == Filter.Result.NEUTRAL);
        msg.put("ToAccount", "111111");
        assertTrue(filter.filter(null, Level.ERROR, null, msg, null) == Filter.Result.DENY);
        filter = MapFilter.createFilter(pairs, "or", null, null);
        filter.start();
        msg = new MapMessage();
        msg.put("ToAccount", "123456");
        msg.put("FromAccount", "211000");
        msg.put("Amount", "1000.00");
        assertTrue(filter.isStarted());
        assertTrue(filter.filter(null, Level.DEBUG, null, msg, null) == Filter.Result.NEUTRAL);
        msg.put("ToAccount", "111111");
        assertTrue(filter.filter(null, Level.ERROR, null, msg, null) == Filter.Result.NEUTRAL);
    }
View Full Code Here

    map.put("test2", "two");
    logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28), 2);
    logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new MapMessage(map), null, map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29), 2);
    ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>(map.values()));
    logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
        Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"), null,
        stack, "none", new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 30), 20000000);
    logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL, new MapMessage(map),
        null, map, stack, null, new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
    rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
  }
View Full Code Here

        assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
        assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
        final Logger logger = LogManager.getLogger(MapFilterTest.class);
        final Map<String, String> eventMap = new HashMap<String, String>();
        eventMap.put("eventId", "Login");
        logger.debug(new MapMessage(eventMap));
        final Map<String,Appender<?>> appenders = config.getAppenders();
        final Appender app = appenders.get("LIST");
        assertNotNull("No List appender", app);
        @SuppressWarnings("unchecked")
        final List<String> msgs = ((ListAppender<String>) app).getMessages();
View Full Code Here

public class MapPatternConverterTest {

    @Test
    public void testConverter() {

        MapMessage msg = new MapMessage();
        msg.put("subject", "I");
        msg.put("verb", "love");
        msg.put("object", "Log4j");
        MapPatternConverter converter = MapPatternConverter.newInstance(null);
        LogEvent event = new Log4jLogEvent("MyLogger", null, null, Level.DEBUG, msg, null);
        StringBuilder sb = new StringBuilder();
        converter.format(event, sb);
        String str = sb.toString();
View Full Code Here

    }

    @Test
    public void testConverterWithKey() {

        MapMessage msg = new MapMessage();
        msg.put("subject", "I");
        msg.put("verb", "love");
        msg.put("object", "Log4j");
        MapPatternConverter converter = MapPatternConverter.newInstance(new String[] {"object"});
        LogEvent event = new Log4jLogEvent("MyLogger", null, null, Level.DEBUG, msg, null);
        StringBuilder sb = new StringBuilder();
        converter.format(event, sb);
        String str = sb.toString();
View Full Code Here

        assertNotNull("No events generated", list);
        assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
        LogEvent event = list.get(0);
        Message m = event.getMessage();
        assertTrue("Message is not a MapMessage", m instanceof MapMessage);
        MapMessage message = (MapMessage) m;
        Map<String, String> map = message.getData();
        assertNotNull("No Map", map);
        assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size() == 3);
        String value = map.get("Key1");
        assertEquals("Apache", value);
        app.clear();
View Full Code Here

    map.put("test2", "two");
    logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28), 2);
    logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new MapMessage(map), null, map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29), 2);
    logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
        Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"), null,
        new ThreadContext.ImmutableStack(map.values()), "none", new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 30), 20000000);
    logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL, new MapMessage(map),
        null, map, new ThreadContext.ImmutableStack(map.values()), null, new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
    rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
  }
View Full Code Here

    public void testFilter() {
        KeyValuePair[] pairs = new KeyValuePair[] { new KeyValuePair("FromAccount", "211000"),
                                                    new KeyValuePair("ToAccount", "123456")};
        MapFilter filter = MapFilter.createFilter(pairs, "and", null, null);
        filter.start();
        MapMessage msg = new MapMessage();
        msg.put("ToAccount", "123456");
        msg.put("FromAccount", "211000");
        msg.put("Amount", "1000.00");
        assertTrue(filter.isStarted());
        assertTrue(filter.filter(null, Level.DEBUG, null, msg, null) == Filter.Result.NEUTRAL);
        msg.put("ToAccount", "111111");
        assertTrue(filter.filter(null, Level.ERROR, null, msg, null) == Filter.Result.DENY);
        filter = MapFilter.createFilter(pairs, "or", null, null);
        filter.start();
        msg = new MapMessage();
        msg.put("ToAccount", "123456");
        msg.put("FromAccount", "211000");
        msg.put("Amount", "1000.00");
        assertTrue(filter.isStarted());
        assertTrue(filter.filter(null, Level.DEBUG, null, msg, null) == Filter.Result.NEUTRAL);
        msg.put("ToAccount", "111111");
        assertTrue(filter.filter(null, Level.ERROR, null, msg, null) == Filter.Result.NEUTRAL);
    }
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.message.MapMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.