本文整理汇总了Java中org.apache.log4j.spi.LoggingEvent.getTimeStamp方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.getTimeStamp方法的具体用法?Java LoggingEvent.getTimeStamp怎么用?Java LoggingEvent.getTimeStamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.spi.LoggingEvent
的用法示例。
在下文中一共展示了LoggingEvent.getTimeStamp方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: append
import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public void append(LoggingEvent event) {
boolean displayIsFine = display == null || display.isDisposed();
boolean parentIsFine = parent == null || parent.isDisposed();
if(displayIsFine || parentIsFine || text == null) {
return;
}
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale);
Date time = new Date(event.getTimeStamp());
String dateTime = dateTimeFormat.format(time);
String excMessage;
Object message = event.getMessage();
if (message instanceof String) {
excMessage = (String) message;
} else {
return;
}
final String logMessage = String.format("[%s] %s%n", dateTime, excMessage);
parent.getDisplay().asyncExec(() -> {
if (!text.isDisposed()) {
text.append(logMessage);
}
});
}
示例2: LogMessage
import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
/**
* Constructs an instance from a Log4J event, using the specified layout.
*
* @throws RuntimeException if any error occurred during formatting or conversion.
* Will include any root cause other than UnsupportedEncodingException.
*/
public LogMessage(LoggingEvent event, Layout layout)
{
try
{
StringWriter out = new StringWriter(1024);
out.write(layout.format(event));
if ((event.getThrowableInformation() != null) && layout.ignoresThrowable())
{
for (String traceline : event.getThrowableStrRep())
{
out.write(traceline);
out.write(Layout.LINE_SEP);
}
}
out.close();
this.timestamp = event.getTimeStamp();
this.message = out.toString();
this.messageBytes = this.message.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("UnsupportedEncodingException when converting to UTF-8");
}
catch (Exception ex)
{
throw new RuntimeException("error creating LogMessage", ex);
}
}
示例3: defaultLogFormat
import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
static private Object defaultLogFormat(LoggingEvent loggingEvent) {
LoggingEventX eventX = new LoggingEventX(loggingEvent.getFQNOfLoggerClass(), loggingEvent.getLogger()
, loggingEvent.getTimeStamp(), loggingEvent.getLevel(), loggingEvent.getMessage(),
loggingEvent.getThreadName(), loggingEvent.getThrowableInformation(), loggingEvent.getNDC(),
loggingEvent.getLocationInformation(), loggingEvent.getProperties());
eventX.setLogTime(new Date(loggingEvent.getTimeStamp()));
eventX.setLogLevel(eventX.getLevel().toString());
return eventX;
}
示例4: getLogEvents
import org.apache.log4j.spi.LoggingEvent; //导入方法依赖的package包/类
public LoggingEvent[] getLogEvents() {
// create a snapshot by copying the complete storage
LoggingEvent[] events = new LoggingEvent[this.eventRing.length];
System.arraycopy(this.eventRing, 0, events, 0, this.eventRing.length);
// store the index of the next element to be stored in the rrStorage
// this should be the oldest entry
int nextEntryIndex = (this.currentPosition + 1) % this.eventRing.length;
LoggingEvent[] sortedEvents;
if (events[nextEntryIndex] == null) {
// event entry has not yet been filled completely, start at zero
sortedEvents = new LoggingEvent[nextEntryIndex];
for (int i = 0; i < sortedEvents.length; i++) {
sortedEvents[i] = events[i];
}
// the storage position might have changed between copying the array and
// calculating the next entry index, compare with oldest entry
} else {
// find the oldest entry by comparing the timestamps
int oldestEntryIndex = -1;
long oldestEntryTimestamp = Long.MAX_VALUE;
LoggingEvent entry;
long entryTimestamp;
for (int entryIndex = 0; entryIndex < events.length; entryIndex++) {
// FIXME <= ? start at the nextEntryIndex? Maybe backwards?
if ((entry = events[entryIndex]) != null && (entryTimestamp = entry.getTimeStamp()) < oldestEntryTimestamp) {
oldestEntryIndex = entryIndex;
oldestEntryTimestamp = entryTimestamp;
}
} // FOR
// if the next entry index and oldest entry index are different and have the same timestamp
// (which only happens if much logging is done), use the next entry index
if (nextEntryIndex != oldestEntryIndex && oldestEntryTimestamp == events[nextEntryIndex].getTimeStamp())
oldestEntryIndex = nextEntryIndex;
// sort the events into a new array
// LoggingEvent[] sortedEvents = new LoggingEvent[events.length];
sortedEvents = new LoggingEvent[events.length];
for (int i = 0; i < sortedEvents.length; i++) {
sortedEvents[i] = events[oldestEntryIndex++ % events.length];
}
}
// throw away the old array
events = null;
return (sortedEvents);
}