本文整理了Java中org.apache.log4j.Layout.format()
方法的一些代码示例,展示了Layout.format()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.format()
方法的具体详情如下:
包路径:org.apache.log4j.Layout
类名称:Layout
方法名:format
[英]Implement this method to create your own layout format.
[中]实现此方法以创建自己的布局格式。
代码示例来源:origin: pentaho/pentaho-kettle
public void doAppend( LoggingEvent event ) {
String line = layout.format( event );
System.out.println( line );
}
代码示例来源:origin: log4j/log4j
/**
* By default getLogStatement sends the event to the required Layout object.
* The layout will format the given pattern into a workable SQL string.
*
* Overriding this provides direct access to the LoggingEvent
* when constructing the logging statement.
*
*/
protected String getLogStatement(LoggingEvent event) {
return getLayout().format(event);
}
代码示例来源:origin: pentaho/pentaho-kettle
public void doAppend( LoggingEvent event ) {
String line = layout.format( event ) + Const.CR;
try {
pipedOutputStream.write( line.getBytes() );
} catch ( IOException e ) {
System.out.println( "Unable to write to piped output stream : " + e.getMessage() );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public void doAppend( LoggingEvent event ) {
String line = layout.format( event ) + Const.CR;
try {
fileOutputStream.write( line.getBytes( Const.XML_ENCODING ) );
} catch ( IOException e ) {
System.out.println( "Unable to close Logging file [" + file.getName() + "] : " + e.getMessage() );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public void doAppend( LoggingEvent event ) {
String line = layout.format( event ) + Const.CR;
buffer.append( line );
// See if we don't have too many lines on board...
nrLines++;
if ( maxNrLines > 0 && nrLines > maxNrLines ) {
buffer.delete( 0, line.length() );
nrLines--;
}
for ( BufferChangedListener listener : bufferChangedListeners ) {
listener.contentWasAdded( buffer, line, nrLines );
}
}
代码示例来源:origin: killme2008/Metamorphosis
public List<String> getLogs(long timestamp) {
List<String> rt = new ArrayList<String>();
List<LoggingEvent> copiedEvents = this.getEvents();
for (LoggingEvent event : copiedEvents) {
if (event.timeStamp > timestamp) {
rt.add(this.layout.format(event));
}
}
return rt;
}
代码示例来源: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
/** 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
sbuf.append(layout.format(event));
if(layout.ignoresThrowable()) {
String[] s = event.getThrowableStrRep();
代码示例来源: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: 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
packet = String.valueOf(event.getMessage());
} else {
packet = layout.format(event);
代码示例来源: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
@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: cloudfoundry/uaa
packet = String.valueOf(event.getMessage());
} else {
packet = layout.format(event);
代码示例来源: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: apache/flume
loggingEvent.getNDC(), loggingEvent.getLocationInformation(),
loggingEvent.getProperties());
msg = layout.format(singleLoggingEvent);
} else {
msg = message.toString();
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* By default getLogStatement sends the event to the required Layout object.
* The layout will format the given pattern into a workable SQL string.
*
* Overriding this provides direct access to the LoggingEvent
* when constructing the logging statement.
*
*/
protected String getLogStatement(LoggingEvent event) {
return getLayout().format(event);
}
代码示例来源:origin: openmrs/openmrs-core
public List<String> getLogLines() {
List<String> logLines = new ArrayList<>(buffer.size());
Layout layout = this.getLayout();
for (Object aBuffer : buffer) {
LoggingEvent loggingEvent = (LoggingEvent) aBuffer;
logLines.add(layout.format(loggingEvent));
}
return logLines;
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!