本文整理了Java中org.apache.logging.log4j.core.Layout
类的一些代码示例,展示了Layout
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout
类的具体详情如下:
包路径:org.apache.logging.log4j.core.Layout
类名称:Layout
[英]Lays out a LogEvent in different formats. The formats are:
Since 2.6, Layouts can Encoder#encode(Object,ByteBufferDestination) a LogEvent directly to a ByteBufferDestination without creating temporary intermediary objects.
[中]以不同的格式显示日志事件。格式如下:
*字节[]
*可序列化的实现者,如byte[]
*串
*日志事件
从2.6开始,布局可以对(对象、ByteBufferDestination)日志事件直接编码到ByteBufferDestination,而无需创建临时中间对象。
代码示例来源:origin: org.apache.logging.log4j/log4j-core
public String formatEvent(final LogEvent event, final Layout<?> layout) {
return new String(layout.toByteArray(event));
}
}
代码示例来源:origin: javamelody/javamelody
/**
* {@inheritDoc}
*/
@Override
public void append(final LogEvent event) {
final Throwable throwable = event.getThrown();
final String message = getLayout().toSerializable(event).toString();
LoggingHandler.addErrorLogToCounter(message, throwable);
}
}
代码示例来源:origin: apache/hive
private HushableRandomAccessFileAppender(final String name, final Layout<? extends Serializable> layout,
final Filter filter, final RandomAccessFileManager manager, final String filename,
final boolean ignoreExceptions, final boolean immediateFlush, final Advertiser advertiser) {
super(name, layout, filter, ignoreExceptions, immediateFlush, manager);
if (advertiser != null) {
final Map<String, String> configuration = new HashMap<>(
layout.getContentFormat());
configuration.putAll(manager.getContentFormat());
configuration.put("contentType", layout.getContentType());
configuration.put("name", name);
advertisement = advertiser.advertise(configuration);
}
this.fileName = filename;
this.advertiser = advertiser;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@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();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@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 Destination content = new Destination();
content.byteBuffer.put(layout.getHeader());
layout.encode(event, content);
content.getByteBuffer().flip();
final byte[] record = new byte[content.getByteBuffer().remaining()];
content.getByteBuffer().get(record);
data.add(record);
} else {
final Destination content = new Destination();
layout.encode(event, content);
content.getByteBuffer().flip();
final byte[] record = new byte[content.getByteBuffer().remaining()];
content.getByteBuffer().get(record);
write(record);
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
urlConnection.setReadTimeout(readTimeoutMillis);
if (layout.getContentType() != null) {
urlConnection.setRequestProperty("Content-Type", layout.getContentType());
final byte[] msg = layout.toByteArray(event);
urlConnection.setFixedLengthStreamingMode(msg.length);
urlConnection.connect();
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private RandomAccessFileAppender(final String name, final Layout<? extends Serializable> layout,
final Filter filter, final RandomAccessFileManager manager, final String filename,
final boolean ignoreExceptions, final boolean immediateFlush, final Advertiser advertiser) {
super(name, layout, filter, ignoreExceptions, immediateFlush, manager);
if (advertiser != null) {
final Map<String, String> configuration = new HashMap<>(
layout.getContentFormat());
configuration.putAll(manager.getContentFormat());
configuration.put("contentType", layout.getContentType());
configuration.put("name", name);
advertisement = advertiser.advertise(configuration);
}
this.fileName = filename;
this.advertiser = advertiser;
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
protected void directEncodeEvent(final LogEvent event) {
getLayout().encode(event, manager);
if (this.immediateFlush || event.isEndOfBatch()) {
manager.flush();
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
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);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
/**
* Send the contents of the cyclic buffer as an e-mail message.
* @param layout The layout for formatting the events.
* @param appendEvent The event that triggered the send.
*/
public void sendEvents(final Layout<?> layout, final LogEvent appendEvent) {
if (message == null) {
connect(appendEvent);
}
try {
final LogEvent[] priorEvents = buffer.removeAll();
// LOG4J-310: log appendEvent even if priorEvents is empty
final byte[] rawBytes = formatContentToBytes(priorEvents, appendEvent, layout);
final String contentType = layout.getContentType();
final String encoding = getEncoding(rawBytes, contentType);
final byte[] encodedBytes = encodeContentToBytes(rawBytes, encoding);
final InternetHeaders headers = getHeaders(contentType, encoding);
final MimeMultipart mp = getMimeMultipart(encodedBytes, headers);
sendMultipartMessage(message, mp);
} catch (final MessagingException | IOException | RuntimeException e) {
logError("Caught exception while sending e-mail notification.", e);
throw new LoggingException("Error occurred while sending email", e);
}
}
代码示例来源:origin: apache/geode
private void doAppendToLogWriter(final ManagerLogWriter logWriter, final LogEvent event) {
byte[] bytes = getLayout().toByteArray(event);
if (bytes != null && bytes.length > 0) {
logWriter.writeFormattedMessage(new String(bytes, Charset.defaultCharset()));
}
if (debug) {
events.add(event);
}
}
代码示例来源:origin: info.xiancloud/xian-gelf-common
@Override
public String getFormattedMessage() {
return layout.toSerializable(logEvent).toString();
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private RollingFileAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter,
final RollingFileManager manager, final String fileName, final String filePattern,
final boolean ignoreExceptions, final boolean immediateFlush, final Advertiser advertiser) {
super(name, layout, filter, ignoreExceptions, immediateFlush, manager);
if (advertiser != null) {
final Map<String, String> configuration = new HashMap<>(layout.getContentFormat());
configuration.put("contentType", layout.getContentType());
configuration.put("name", name);
advertisement = advertiser.advertise(configuration);
}
this.fileName = fileName;
this.filePattern = filePattern;
this.advertiser = advertiser;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
public String formatEvent(final LogEvent event, final Layout<?> layout) {
return new String(layout.toByteArray(event));
}
}
代码示例来源:origin: org.infinispan/infinispan-commons-test
@Override
public void append(LogEvent event) {
if (threadFilter.test(Thread.currentThread())) {
logs.add((String) getLayout().toSerializable(event));
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private RollingRandomAccessFileAppender(final String name, final Layout<? extends Serializable> layout,
final Filter filter, final RollingRandomAccessFileManager manager, final String fileName,
final String filePattern, final boolean ignoreExceptions,
final boolean immediateFlush, final int bufferSize, final Advertiser advertiser) {
super(name, layout, filter, ignoreExceptions, immediateFlush, manager);
if (advertiser != null) {
final Map<String, String> configuration = new HashMap<>(layout.getContentFormat());
configuration.put("contentType", layout.getContentType());
configuration.put("name", name);
advertisement = advertiser.advertise(configuration);
} else {
advertisement = null;
}
this.fileName = fileName;
this.filePattern = filePattern;
this.advertiser = advertiser;
}
代码示例来源:origin: apache/rocketmq
/**
* Info,error,warn,callback method implementation
*/
public void append(LogEvent event) {
if (null == producer) {
return;
}
byte[] data = this.getLayout().toByteArray(event);
try {
Message msg = new Message(topic, tag, data);
msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOG4J2_APPENDER);
//Send message and do not wait for the ack from the message broker.
producer.sendOneway(msg);
} catch (Exception e) {
ErrorHandler handler = this.getHandler();
if (handler != null) {
String msg = new String(data);
handler.error("Could not send message in RocketmqLog4j2Appender [" + this.getName() + "].Message is : " + msg, e);
}
}
}
代码示例来源:origin: org.mycore.mir/mir-wizard
@Override
public void append(LogEvent event) {
writer.write(this.getLayout().toSerializable(event).toString());
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
protected SocketAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter,
final AbstractSocketManager manager, final boolean ignoreExceptions, final boolean immediateFlush,
final Advertiser advertiser) {
super(name, layout, filter, ignoreExceptions, immediateFlush, manager);
if (advertiser != null) {
final Map<String, String> configuration = new HashMap<>(layout.getContentFormat());
configuration.putAll(manager.getContentFormat());
configuration.put("contentType", layout.getContentType());
configuration.put("name", name);
this.advertisement = advertiser.advertise(configuration);
} else {
this.advertisement = null;
}
this.advertiser = advertiser;
}
代码示例来源:origin: didi/DDMQ
/**
* Info,error,warn,callback method implementation
*/
public void append(LogEvent event) {
if (null == producer) {
return;
}
byte[] data = this.getLayout().toByteArray(event);
try {
Message msg = new Message(topic, tag, data);
msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOG4J2_APPENDER);
//Send message and do not wait for the ack from the message broker.
producer.sendOneway(msg);
} catch (Exception e) {
ErrorHandler handler = this.getHandler();
if (handler != null) {
String msg = new String(data);
handler.error("Could not send message in RocketmqLog4j2Appender [" + this.getName() + "].Message is : " + msg, e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!