本文整理汇总了Java中org.apache.logging.log4j.core.layout.SerializedLayout类的典型用法代码示例。如果您正苦于以下问题:Java SerializedLayout类的具体用法?Java SerializedLayout怎么用?Java SerializedLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializedLayout类属于org.apache.logging.log4j.core.layout包,在下文中一共展示了SerializedLayout类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: launchCreatesAndStartsAppenderAndProcessesMessages
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
@Test
public void launchCreatesAndStartsAppenderAndProcessesMessages() throws Exception {
final MessageInput messageInput = mock(MessageInput.class);
transport.launch(messageInput);
final DirectConsumingAppender appender = transport.getAppender();
assertThat(appender.getName()).isEqualTo("graylog-plugin-internal-logs");
assertThat(appender.getLayout()).isInstanceOf(SerializedLayout.class);
assertThat(appender.isStarted()).isTrue();
final MutableLogEvent logEvent = new MutableLogEvent();
logEvent.setMessage(new SimpleMessage("Processed"));
logEvent.setLevel(Level.ERROR);
appender.append(logEvent);
verify(messageInput, times(1)).processRawMessage(any(RawMessage.class));
final MutableLogEvent ignoredLogEvent = new MutableLogEvent();
ignoredLogEvent.setMessage(new SimpleMessage("Ignored"));
ignoredLogEvent.setLevel(Level.TRACE);
appender.append(ignoredLogEvent);
verifyNoMoreInteractions(messageInput);
}
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:23,代码来源:SerializedLogEventTransportTest.java
示例2: append
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
@Override
public synchronized void append(final LogEvent event) {
final Layout<? extends Serializable> layout = getLayout();
if (layout == null) {
if (event instanceof MutableLogEvent) {
// must take snapshot or subsequent calls to logger.log() will modify this event
events.add(((MutableLogEvent) event).createMemento());
} else {
events.add(event);
}
} else if (layout instanceof SerializedLayout) {
final byte[] header = layout.getHeader();
final byte[] content = layout.toByteArray(event);
final byte[] record = new byte[header.length + content.length];
System.arraycopy(header, 0, record, 0, header.length);
System.arraycopy(content, 0, record, header.length, content.length);
data.add(record);
} else {
write(layout.toByteArray(event));
}
if (countDownLatch != null) {
countDownLatch.countDown();
}
}
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:25,代码来源:ListAppender.java
示例3: append
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
@Override
public synchronized void append(final LogEvent event) {
final Layout<? extends Serializable> layout = getLayout();
if (layout == null) {
events.add(event);
} else if (layout instanceof SerializedLayout) {
final byte[] header = layout.getHeader();
final byte[] content = layout.toByteArray(event);
final byte[] record = new byte[header.length + content.length];
System.arraycopy(header, 0, record, 0, header.length);
System.arraycopy(content, 0, record, header.length, content.length);
data.add(record);
} else {
write(layout.toByteArray(event));
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:ListAppender.java
示例4: ListAppender
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
public ListAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout, final boolean newline,
final boolean raw) {
super(name, filter, layout);
this.newLine = newline;
this.raw = raw;
if (layout != null && !(layout instanceof SerializedLayout)) {
final byte[] bytes = layout.getHeader();
if (bytes != null) {
write(bytes);
}
}
}
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:13,代码来源:ListAppender.java
示例5: createAppender
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
@PluginFactory
public static KafkaAppender createAppender(@PluginAttribute("name") final String name,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginAttribute("topic") final String topic,
@PluginAttribute("enable") String enable,
@PluginAttribute("syncsend") String syncsend,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Properties") final Property[] properties) {
boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
boolean enableKafka = Booleans.parseBoolean(enable, true);
boolean sync = Booleans.parseBoolean(syncsend, false);
KafkaProducer<String, String> producer = null;
Map<String, Object> props = new HashMap<String, Object>();
for (Property property : properties) {
props.put(property.getName(), property.getValue());
}
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
if(enableKafka)
producer = new KafkaProducer<String, String>(props);
if(layout == null) {
layout = SerializedLayout.createLayout();
}
return new KafkaAppender(name, filter, layout, ignoreExceptions, producer , topic, sync);
}
开发者ID:omkreddy,项目名称:log4j2-kafka-appender,代码行数:32,代码来源:KafkaAppender.java
示例6: createAppender
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
/**
* Create a JMSQueueAppender.
* @param name The name of the Appender.
* @param factoryName The fully qualified class name of the InitialContextFactory.
* @param providerURL The URL of the provider to use.
* @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
* will create a URL context factory
* @param securityPrincipalName The name of the identity of the Principal.
* @param securityCredentials The security credentials of the Principal.
* @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
* @param queueBindingName The name to use to locate the Queue.
* @param userName The user ID to use to create the Queue Connection.
* @param password The password to use to create the Queue Connection.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The JMSQueueAppender.
*/
@PluginFactory
public static JMSQueueAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("factoryName") final String factoryName,
@PluginAttribute("providerURL") final String providerURL,
@PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
@PluginAttribute("securityPrincipalName") final String securityPrincipalName,
@PluginAttribute("securityCredentials") final String securityCredentials,
@PluginAttribute("factoryBindingName") final String factoryBindingName,
@PluginAttribute("queueBindingName") final String queueBindingName,
@PluginAttribute("userName") final String userName,
@PluginAttribute("password") final String password,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for JMSQueueAppender");
return null;
}
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final JMSQueueManager manager = JMSQueueManager.getJMSQueueManager(factoryName, providerURL, urlPkgPrefixes,
securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
if (manager == null) {
return null;
}
if (layout == null) {
layout = SerializedLayout.createLayout();
}
return new JMSQueueAppender(name, filter, layout, manager, ignoreExceptions);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:50,代码来源:JMSQueueAppender.java
示例7: createAppender
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
/**
* Create a JMSTopicAppender.
* @param name The name of the Appender.
* @param factoryName The fully qualified class name of the InitialContextFactory.
* @param providerURL The URL of the provider to use.
* @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
* will create a URL context factory
* @param securityPrincipalName The name of the identity of the Principal.
* @param securityCredentials The security credentials of the Principal.
* @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
* @param topicBindingName The name to use to locate the Topic.
* @param userName The userid to use to create the Topic Connection.
* @param password The password to use to create the Topic Connection.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The JMSTopicAppender.
*/
@PluginFactory
public static JMSTopicAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("factoryName") final String factoryName,
@PluginAttribute("providerURL") final String providerURL,
@PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
@PluginAttribute("securityPrincipalName") final String securityPrincipalName,
@PluginAttribute("securityCredentials") final String securityCredentials,
@PluginAttribute("factoryBindingName") final String factoryBindingName,
@PluginAttribute("topicBindingName") final String topicBindingName,
@PluginAttribute("userName") final String userName,
@PluginAttribute("password") final String password,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for JMSQueueAppender");
return null;
}
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final JMSTopicManager manager = JMSTopicManager.getJMSTopicManager(factoryName, providerURL, urlPkgPrefixes,
securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
if (manager == null) {
return null;
}
if (layout == null) {
layout = SerializedLayout.createLayout();
}
return new JMSTopicAppender(name, filter, layout, manager, ignoreExceptions);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:51,代码来源:JMSTopicAppender.java
示例8: tryAppend
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
final Layout<? extends Serializable> layout = getLayout();
byte[] data;
if (layout instanceof SerializedLayout) {
final byte[] header = layout.getHeader();
final byte[] body = layout.toByteArray(event);
data = new byte[header.length + body.length];
System.arraycopy(header, 0, data, 0, header.length);
System.arraycopy(body, 0, data, header.length, body.length);
} else {
data = layout.toByteArray(event);
}
manager.send(data);
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:15,代码来源:KafkaAppender.java
示例9: Builder
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
private Builder() {
this.layout = SerializedLayout.createLayout();
this.ignoreExceptions = true;
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:5,代码来源:RocketmqLog4j2Appender.java
示例10: appenderUsesSerializedLayout
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
@Test
public void appenderUsesSerializedLayout() throws Exception {
assertThat(appender.getLayout()).isInstanceOf(SerializedLayout.class);
}
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:5,代码来源:DirectConsumingAppenderTest.java
示例11: createAppender
import org.apache.logging.log4j.core.layout.SerializedLayout; //导入依赖的package包/类
/**
*
* @param host The name of the host to connect to.
* @param portNum The port to connect to on the target host.
* @param protocol The Protocol to use.
* @param delay The interval in which failed writes should be retried.
* @param immediateFail True if the write should fail if no socket is immediately available.
* @param name The name of the Appender.
* @param immediateFlush "true" if data should be flushed on each write.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
* @param config The Configuration
* @return A SocketAppender.
*/
@PluginFactory
public static SocketAppender createAppender(
@PluginAttribute("host") final String host,
@PluginAttribute("port") final String portNum,
@PluginAttribute("protocol") final String protocol,
@PluginAttribute("reconnectionDelay") final String delay,
@PluginAttribute("immediateFail") final String immediateFail,
@PluginAttribute("name") final String name,
@PluginAttribute("immediateFlush") final String immediateFlush,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("advertise") final String advertise,
@PluginConfiguration final Configuration config) {
boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean fail = Booleans.parseBoolean(immediateFail, true);
final int reconnectDelay = AbstractAppender.parseInt(delay, 0);
final int port = AbstractAppender.parseInt(portNum, 0);
if (layout == null) {
layout = SerializedLayout.createLayout();
}
if (name == null) {
LOGGER.error("No name provided for SocketAppender");
return null;
}
final Protocol p = EnglishEnums.valueOf(Protocol.class, protocol != null ? protocol : Protocol.TCP.name());
if (p.equals(Protocol.UDP)) {
isFlush = true;
}
final AbstractSocketManager manager = createSocketManager(p, host, port, reconnectDelay, fail, layout);
if (manager == null) {
return null;
}
return new SocketAppender(name, layout, filter, manager, ignoreExceptions, isFlush,
isAdvertise ? config.getAdvertiser() : null);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:61,代码来源:SocketAppender.java
注:本文中的org.apache.logging.log4j.core.layout.SerializedLayout类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论