当前位置: 首页>>代码示例>>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;未经允许,请勿转载。