Java Code Examples for org.apache.logging.log4j.core.impl.Log4jLogEvent#getTimeMillis()
The following examples show how to use
org.apache.logging.log4j.core.impl.Log4jLogEvent#getTimeMillis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log4j1XmlLayoutTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testWithoutThrown() { final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(false, true); final Log4jLogEvent event = Log4jLogEvent.newBuilder() .setLoggerName("a.B") .setLevel(Level.INFO) .setMessage(new SimpleMessage("Hello, World")) .setTimeMillis(System.currentTimeMillis() + 17) .build(); final String result = layout.toSerializable(event); final String expected = "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" + "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" + "</log4j:event>\r\n\r\n"; assertEquals(expected, result); }
Example 2
Source File: Log4j1XmlLayoutTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void testWithoutThrown() { final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(false, true); final Log4jLogEvent event = Log4jLogEvent.newBuilder() .setLoggerName("a.B") .setLevel(Level.INFO) .setMessage(new SimpleMessage("Hello, World")) .setTimeMillis(System.currentTimeMillis() + 17) .build(); final String result = layout.toSerializable(event); final String expected = "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" + "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" + "</log4j:event>\r\n\r\n"; assertEquals(expected, result); }
Example 3
Source File: Log4j1XmlLayoutTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testWithPropertiesAndLocationInfo() { final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(true, true); final StringMap contextMap = ContextDataFactory.createContextData(2); contextMap.putValue("key1", "value1"); contextMap.putValue("key2", "value2"); final Log4jLogEvent event = Log4jLogEvent.newBuilder() .setLoggerName("a.B") .setLevel(Level.INFO) .setMessage(new SimpleMessage("Hello, World")) .setTimeMillis(System.currentTimeMillis() + 17) .setIncludeLocation(true) .setSource(new StackTraceElement("pack.MyClass", "myMethod", "MyClass.java", 17)) .setContextData(contextMap) .build(); final String result = layout.toSerializable(event); final String expected = "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" + "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" + "<log4j:locationInfo class=\"pack.MyClass\" method=\"myMethod\" file=\"MyClass.java\" line=\"17\"/>\r\n" + "<log4j:properties>\r\n" + "<log4j:data name=\"key1\" value=\"value1\"/>\r\n" + "<log4j:data name=\"key2\" value=\"value2\"/>\r\n" + "</log4j:properties>\r\n"+ "</log4j:event>\r\n\r\n"; assertEquals(expected, result); }
Example 4
Source File: Log4j1XmlLayoutTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testWithPropertiesAndLocationInfo() { final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(true, true); final StringMap contextMap = ContextDataFactory.createContextData(2); contextMap.putValue("key1", "value1"); contextMap.putValue("key2", "value2"); final Log4jLogEvent event = Log4jLogEvent.newBuilder() .setLoggerName("a.B") .setLevel(Level.INFO) .setMessage(new SimpleMessage("Hello, World")) .setTimeMillis(System.currentTimeMillis() + 17) .setIncludeLocation(true) .setSource(new StackTraceElement("pack.MyClass", "myMethod", "MyClass.java", 17)) .setContextData(contextMap) .build(); final String result = layout.toSerializable(event); final String expected = "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" + "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" + "<log4j:locationInfo class=\"pack.MyClass\" method=\"myMethod\" file=\"MyClass.java\" line=\"17\"/>\r\n" + "<log4j:properties>\r\n" + "<log4j:data name=\"key1\" value=\"value1\"/>\r\n" + "<log4j:data name=\"key2\" value=\"value2\"/>\r\n" + "</log4j:properties>\r\n"+ "</log4j:event>\r\n\r\n"; assertEquals(expected, result); }