本文整理匯總了Java中org.apache.logging.log4j.core.impl.Log4jLogEvent.Builder類的典型用法代碼示例。如果您正苦於以下問題:Java Builder類的具體用法?Java Builder怎麽用?Java Builder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Builder類屬於org.apache.logging.log4j.core.impl.Log4jLogEvent包,在下文中一共展示了Builder類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPropertiesWithoutSubstitution
import org.apache.logging.log4j.core.impl.Log4jLogEvent.Builder; //導入依賴的package包/類
@SuppressWarnings({"deprecation"})
@Test
public void testPropertiesWithoutSubstitution() {
assertNull("null propertiesList", createForProperties(null).getPropertyList());
assertNull("null property Map", createForProperties(null).getProperties());
final Property[] all = new Property[] {
Property.createProperty("key1", "value1"),
Property.createProperty("key2", "value2"),
};
final LoggerConfig loggerConfig = createForProperties(all);
final List<Property> list = loggerConfig.getPropertyList();
assertEquals("map and list contents equal", new HashSet<>(list),
new HashSet<>(loggerConfig.getPropertyList()));
final Object[] actualList = new Object[1];
loggerConfig.setLogEventFactory(new LogEventFactory() {
@Override
public LogEvent createEvent(final String loggerName, final Marker marker, final String fqcn,
final Level level, final Message data,
final List<Property> properties, final Throwable t) {
actualList[0] = properties;
return new Builder().setTimeMillis(System.currentTimeMillis()).build();
}
});
loggerConfig.log("name", "fqcn", null, Level.INFO, new SimpleMessage("msg"), null);
assertSame("propertiesList passed in as is if no substitutions required", list, actualList[0]);
}
示例2: testPropertiesWithSubstitution
import org.apache.logging.log4j.core.impl.Log4jLogEvent.Builder; //導入依賴的package包/類
@Test
public void testPropertiesWithSubstitution() {
final Property[] all = new Property[] {
Property.createProperty("key1", "value1-${sys:user.name}"),
Property.createProperty("key2", "value2-${sys:user.name}"),
};
final LoggerConfig loggerConfig = createForProperties(all);
final List<Property> list = loggerConfig.getPropertyList();
assertEquals("map and list contents equal", new HashSet<>(list),
new HashSet<>(loggerConfig.getPropertyList()));
final Object[] actualListHolder = new Object[1];
loggerConfig.setLogEventFactory(new LogEventFactory() {
@Override
public LogEvent createEvent(final String loggerName, final Marker marker, final String fqcn,
final Level level, final Message data,
final List<Property> properties, final Throwable t) {
actualListHolder[0] = properties;
return new Builder().setTimeMillis(System.currentTimeMillis()).build();
}
});
loggerConfig.log("name", "fqcn", null, Level.INFO, new SimpleMessage("msg"), null);
assertNotSame("propertiesList with substitutions", list, actualListHolder[0]);
@SuppressWarnings("unchecked")
final List<Property> actualList = (List<Property>) actualListHolder[0];
for (int i = 0; i < list.size(); i++) {
assertEquals("name[" + i + "]", list.get(i).getName(), actualList.get(i).getName());
final String value = list.get(i).getValue().replace("${sys:user.name}", System.getProperty("user.name"));
assertEquals("value[" + i + "]", value, actualList.get(i).getValue());
}
}