本文整理了Java中org.apache.log4j.Layout
类的一些代码示例,展示了Layout
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout
类的具体详情如下:
包路径:org.apache.log4j.Layout
类名称:Layout
[英]Extend this abstract class to create your own log layout format.
[中]扩展此抽象类以创建自己的日志布局格式。
代码示例来源:origin: apache/flume
private List<Event> parseEvents(LoggingEvent loggingEvent) {
Map<String, String> headers = new HashMap<>();
headers.put(Log4jAvroHeaders.LOGGER_NAME.toString(), loggingEvent.getLoggerName());
headers.put(Log4jAvroHeaders.TIMESTAMP.toString(), String.valueOf(loggingEvent.timeStamp));
headers.put(Log4jAvroHeaders.ADDRESS.toString(), clientAddress);
String.valueOf(loggingEvent.getLevel().toInt()));
if (loggingEvent.getMessage() instanceof Collection) {
messages = (Collection) loggingEvent.getMessage();
} else {
loggingEvent.getNDC(), loggingEvent.getLocationInformation(),
loggingEvent.getProperties());
msg = layout.format(singleLoggingEvent);
} else {
msg = message.toString();
代码示例来源:origin: log4j/log4j
public void append(LoggingEvent event) {
StringBuffer sbuf = new StringBuffer();
sbuf.append(layout.format(event));
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if (s != null) {
int len = s.length;
for(int i = 0; i < len; i++) {
sbuf.append(s[i]);
}
}
}
// Normalize the log message level into the supported categories
int nt_category = event.getLevel().toInt();
// Anything above FATAL or below DEBUG is labeled as INFO.
//if (nt_category > FATAL || nt_category < DEBUG) {
// nt_category = INFO;
//}
reportEvent(_handle, sbuf.toString(), nt_category);
}
代码示例来源:origin: log4j/log4j
String t = layout.getHeader();
if(t != null)
sbuf.append(t);
sbuf.append(layout.format(event));
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if (s != null) {
for(int j = 0; j < s.length; j++) {
t = layout.getFooter();
if(t != null) {
sbuf.append(t);
代码示例来源:origin: log4j/log4j
/**
Actual writing occurs here.
<p>Most subclasses of <code>WriterAppender</code> will need to
override this method.
@since 0.9.0 */
protected
void subAppend(LoggingEvent event) {
this.qw.write(this.layout.format(event));
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if (s != null) {
int len = s.length;
for(int i = 0; i < len; i++) {
this.qw.write(s[i]);
this.qw.write(Layout.LINE_SEP);
}
}
}
if(shouldFlush(event)) {
this.qw.flush();
}
}
代码示例来源:origin: log4j/log4j
/** Handles a log event. For this appender, that means writing the
message to each connected client. */
protected void append(LoggingEvent event) {
if(sh != null) {
sh.send(layout.format(event));
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if (s != null) {
StringBuffer buf = new StringBuffer();
for(int i = 0; i < s.length; i++) {
buf.append(s[i]);
buf.append("\r\n");
}
sh.send(buf.toString());
}
}
}
}
代码示例来源:origin: log4j/log4j
public
void append(LoggingEvent event) {
if(!isAsSevereAsThreshold(event.getLevel()))
return;
if (layout != null && layout.getHeader() != null) {
sendLayoutMessage(layout.getHeader());
String packet;
if (layout == null) {
packet = String.valueOf(event.getMessage());
} else {
packet = layout.format(event);
sqw.setLevel(event.getLevel().getSyslogEquivalent());
if (layout == null || layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
if (s != null) {
代码示例来源:origin: QSFT/Doradus
public static String getLog(String level) {
Level lvl = level == null ? Level.DEBUG : Level.toLevel(level);
StringBuilder sb = new StringBuilder();
synchronized(m_sync) {
for(LoggingEvent event: m_backup) {
if(event.getLevel().toInt() < lvl.toInt()) continue;
String log = m_layout.format(event);
sb.append(log);
}
sb.append("\n");
for(LoggingEvent event: m_current) {
if(event.getLevel().toInt() < lvl.toInt()) continue;
String log = m_layout.format(event);
sb.append(log);
}
return sb.toString();
}
}
}
代码示例来源:origin: org.jvnet.hyperjaxb3/maven-hyperjaxb3-plugin
@Override
protected void append(LoggingEvent event) {
if (event.getLevel().equals(Level.TRACE)) {
log.debug(layout.format(event));
} else if (event.getLevel().equals(Level.DEBUG)) {
log.debug(layout.format(event));
} else if (event.getLevel().equals(Level.INFO)) {
log.info(layout.format(event));
} else if (event.getLevel().equals(Level.WARN)) {
log.warn(layout.format(event));
} else if (event.getLevel().equals(Level.ERROR)) {
log.error(layout.format(event));
} else if (event.getLevel().equals(Level.FATAL)) {
log.error(layout.format(event));
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Override
protected void append( LoggingEvent event ) {
String s = layout.format( event );
if ( Level.DEBUG.equals( event.getLevel() ) ) {
log.logDebug( s );
} else if ( Level.ERROR.equals( event.getLevel() )
|| Level.FATAL.equals( event.getLevel() ) ) {
Throwable t = event.getThrowableInformation() == null ? null : event.getThrowableInformation().getThrowable();
if ( t == null ) {
log.logError( s );
} else {
log.logError( s, t );
}
} else if ( Level.TRACE.equals( event.getLevel() ) ) {
log.logRowlevel( s );
} else if ( Level.OFF.equals( event.getLevel() ) ) {
log.logMinimal( s );
} else {
// ALL, WARN, INFO, or others
log.logBasic( s );
}
}
代码示例来源:origin: org.graylog2/syslog4j
protected void append(LoggingEvent event) {
if (!this.initialized) {
_initialize();
}
if (this.initialized) {
int level = event.getLevel().getSyslogEquivalent();
if (this.layout != null) {
String message = this.layout.format(event);
this.syslog.log(level, message);
} else {
String message = event.getRenderedMessage();
this.syslog.log(level, message);
}
}
}
代码示例来源:origin: com.qaprosoft/zafira-client
/**
* Method is called by ExecutorService and publishes message on RabbitMQ
*
* @return loggingEvent
*/
@Override
public LoggingEvent call() throws Exception
{
if(zafiraConnected)
{
String payload = layout.format(loggingEvent);
AMQP.BasicProperties.Builder b = new AMQP.BasicProperties().builder();
b.appId(identifier)
.type(loggingEvent.getLevel().toString())
.correlationId(String.valueOf(correlationId))
.contentType("text/json");
createChannel().basicPublish(exchange, routingKey, b.build(), payload.getBytes());
}
return loggingEvent;
}
}
代码示例来源:origin: ron190/jsql-injection
/**
* Method from Log4j AppenderSkeleton that gets a call for all Log4J events.
* @param event A logging event.
* @see org.apache.log4j.AppenderSkeleton
*/
@Override
public void append(final LoggingEvent event) {
SwingUtilities.invokeLater(() -> this.insertText(
this.layout.format(event),
event.getLevel(),
event.getThrowableInformation()
));
}
代码示例来源:origin: riotfamily/riot
@Override
protected synchronized void append(LoggingEvent event) {
if (lastReportSent + minLagBetweenMails <= System.currentTimeMillis()) {
if (text == null) {
text = new StringBuilder();
String header = getLayout().getHeader();
if (header != null) {
text.append(header);
}
}
text.append(getLayout().format(event));
if (event.getLevel().isGreaterOrEqual(highestSeverity)) {
highestSeverity = event.getLevel();
}
schedule(reportWindow);
}
}
代码示例来源:origin: cloudfoundry/uaa
@Override
public String format(LoggingEvent event) {
if(lineLayout == null) { return messageLayout == null ? event.getRenderedMessage() : messageLayout.format(event); }
String message = event.getRenderedMessage();
String[] lines;
String[] throwable;
if(messageLayout == null && (throwable = event.getThrowableStrRep()) != null) {
lines = throwable;
} else if(message != null) {
lines = message.split("\r?\n");
} else {
lines = new String[0];
}
StringBuffer strBuf = new StringBuffer();
for (String line : lines) {
String formattedLine = lineLayout.format(replaceEventMessageWithoutThrowable(event, line));
strBuf.append(formattedLine);
}
String formattedLines = strBuf.toString();
if (messageLayout == null) return formattedLines;
return messageLayout.format(replaceEventMessage(event, formattedLines));
}
代码示例来源:origin: yacy/yacy_grid_mcp
@Override
public void append(LoggingEvent event) {
if (event == null) return;
String line = this.layout.format(event);
this.lines.add(line);
if (event.getThrowableInformation() != null) {
for (String t: event.getThrowableStrRep()) this.lines.add(t + "\n");
}
clean(this.maxlines);
}
代码示例来源:origin: javamelody/javamelody
/**
* {@inheritDoc}
*/
@Override
protected void append(LoggingEvent event) {
final Throwable throwable;
if (event.getThrowableInformation() == null) {
throwable = null;
} else {
throwable = event.getThrowableInformation().getThrowable();
}
LoggingHandler.addErrorLogToCounter(getLayout().format(event), throwable);
}
代码示例来源:origin: pentaho/pentaho-kettle
public void doAppend( LoggingEvent event ) {
String line = layout.format( event );
System.out.println( line );
}
代码示例来源:origin: broadgsa/gatk
/**
* The string representation for the class data
*
* @return string containing the logging events
* @throws ReviewedGATKException if layout is null
*/
public synchronized String toString() {
final String msgType = logLevelToKeep.toString() + " messages";
if ( loggingEvents.isEmpty() ) {
return "There were no " + new String(msgType).toLowerCase() + ".\n";
} else {
String out = "There were " + Integer.toString(numLoggingEvents) + " " + msgType;
if ( layout == null )
throw new ReviewedGATKException("layout cannot be null");
out += ", the first " + loggingEvents.size() + " are repeated below.\n";
for ( LoggingEvent event : loggingEvents ) {
out += layout.format(event);
}
return out;
}
}
代码示例来源:origin: apache/rocketmq
/**
* Info,error,warn,callback method implementation
*/
public void append(LoggingEvent event) {
if (null == producer) {
return;
}
if (locationInfo) {
event.getLocationInformation();
}
byte[] data = this.layout.format(event).getBytes();
try {
Message msg = new Message(topic, tag, data);
msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOG4J_APPENDER);
//Send message and do not wait for the ack from the message broker.
producer.sendOneway(msg);
} catch (Exception e) {
String msg = new String(data);
errorHandler.error("Could not send message in RocketmqLog4jAppender [" + name + "].Message is :" + msg, e,
ErrorCode.GENERIC_FAILURE);
}
}
代码示例来源:origin: log4j/log4j
/**
Write a footer as produced by the embedded layout's {@link
Layout#getFooter} method. */
protected
void writeFooter() {
if(layout != null) {
String f = layout.getFooter();
if(f != null && this.qw != null) {
this.qw.write(f);
this.qw.flush();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!