本文整理了Java中org.apache.logging.log4j.core.Layout.toByteArray()
方法的一些代码示例,展示了Layout.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.toByteArray()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.Layout
类名称:Layout
方法名:toByteArray
[英]Formats the event suitable for display.
[中]设置适合显示的事件的格式。
代码示例来源:origin: org.apache.logging.log4j/log4j-core
public String formatEvent(final LogEvent event, final Layout<?> layout) {
return new String(layout.toByteArray(event));
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
public String formatEvent(final LogEvent event, final Layout<?> layout) {
return new String(layout.toByteArray(event));
}
}
代码示例来源: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: 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.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: 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);
}
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
protected void writeBuffer(final LogEvent[] priorEvents, final LogEvent appendEvent, final Layout<?> layout,
final OutputStream out) throws IOException {
for (final LogEvent priorEvent : priorEvents) {
final byte[] bytes = layout.toByteArray(priorEvent);
out.write(bytes);
}
final byte[] bytes = layout.toByteArray(appendEvent);
out.write(bytes);
}
代码示例来源: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: rapid7/le_java
@Override
public void append(LogEvent event)
{
final Layout<? extends Serializable> layout = getLayout();
String line = new String(layout.toByteArray(event));
manager.writeLine(line);
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public synchronized void append(final LogEvent event) {
final Layout<? extends Serializable> layout = getLayout();
final byte[] formattedMessage = layout.toByteArray(event);
if (manager.send(getLayout().toByteArray(event))) {
sendRcTrue++;
} else {
sendRcFalse++;
LOGGER.error("Appender {} could not send message {} to JeroMQ {}", getName(), sendRcFalse, formattedMessage);
}
}
代码示例来源:origin: com.amazonaws/aws-lambda-java-log4j2
/**
* Append log event to System.out
* @param event log4j event
*/
public void append(LogEvent event) {
logger.log(super.getLayout().toByteArray(event));
}
}
代码示例来源:origin: aws/aws-lambda-java-libs
/**
* Append log event to System.out
* @param event log4j event
*/
public void append(LogEvent event) {
logger.log(super.getLayout().toByteArray(event));
}
}
代码示例来源:origin: infiniteautomation/ma-core-public
@Override
public void append(LogEvent event) {
readLock.lock();
try{
final byte[] bytes = getLayout().toByteArray(event);
LoggingConsoleRT.instance.addMessage(new String(bytes));
}catch(Exception e){
if(!ignoreExceptions())
throw new AppenderLoggingException(e);
}finally{
readLock.unlock();
}
}
代码示例来源:origin: com.googlecode.openbox/log
@Override
public void append(LogEvent event) {
String logContent = null;
if (justContent) {
logContent = event.getMessage().getFormattedMessage();
} else {
byte[] bytes = getLayout().toByteArray(event);
try {
logContent = new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Reporter.log(logContent);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
protected void writeByteArrayToManager(final LogEvent event) {
final byte[] bytes = getLayout().toByteArray(event);
if (bytes != null && bytes.length > 0) {
manager.write(bytes, this.immediateFlush || event.isEndOfBatch());
}
}
}
代码示例来源:origin: org.springframework.amqp/spring-rabbit
try {
synchronized (this.layoutMutex) {
msgBody = new StringBuilder(new String(getLayout().toByteArray(logEvent), "UTF-8"));
routingKey = new String(this.manager.routingKeyLayout.toByteArray(logEvent),
"UTF-8");
代码示例来源:origin: Azure/azure-event-hubs-java
serializedLogEvent = layout.toByteArray(logEvent);
} else {
serializedLogEvent = StringEncoder.toBytes(logEvent.getMessage().getFormattedMessage(), StandardCharsets.UTF_8);
代码示例来源:origin: com.vlkan.log4j2/log4j2-redis-appender
@Override
public void append(LogEvent event) {
logger.debug("appending: %s", event.getMessage().getFormattedMessage());
if (State.STARTED.equals(state)) {
byte[] eventBytes = layout.toByteArray(event);
throttler.push(eventBytes);
}
}
代码示例来源:origin: tmobile/pacbot
public void append(LogEvent event) {
try {
final byte[] logMessage = getLayout().toByteArray(event);
代码示例来源:origin: org.dblock.log4jna/log4jna-api
/**
* {@inheritDoc}
*/
public void append(LogEvent event) {
if (_handle == null) {
registerEventSource();
}
String s = new String(getLayout().toByteArray(event));
final int messageID = 0x1000;
String[] buffer = { s };
if (Advapi32.INSTANCE.ReportEvent(_handle, getEventLogType(event.getLevel()),
getEventLogCategory(event.getLevel()), messageID, null, buffer.length, 0, buffer, null) == false) {
Exception e = new Win32Exception(Kernel32.INSTANCE.GetLastError());
getHandler().error("Failed to report event [" + s + "].", event, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!