當前位置: 首頁>>代碼示例>>Java>>正文


Java LoggingEvent.getTimeStamp方法代碼示例

本文整理匯總了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);
        }
    });
}
 
開發者ID:technology16,項目名稱:pgsqlblocks,代碼行數:25,代碼來源:UIAppender.java

示例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);
    }
}
 
開發者ID:kdgregory,項目名稱:log4j-aws-appenders,代碼行數:36,代碼來源:LogMessage.java

示例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;
    }
 
開發者ID:Crab2died,項目名稱:log4j-redis-appender,代碼行數:12,代碼來源:RedisAppender.java

示例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);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:51,代碼來源:RingBufferAppender.java


注:本文中的org.apache.log4j.spi.LoggingEvent.getTimeStamp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。