当前位置: 首页>>代码示例>>Java>>正文


Java LogRecord.getMillis方法代码示例

本文整理汇总了Java中java.util.logging.LogRecord.getMillis方法的典型用法代码示例。如果您正苦于以下问题:Java LogRecord.getMillis方法的具体用法?Java LogRecord.getMillis怎么用?Java LogRecord.getMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.logging.LogRecord的用法示例。


在下文中一共展示了LogRecord.getMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLogRecordValue

import java.util.logging.LogRecord; //导入方法依赖的package包/类
private Integer getLogRecordValue(int sampleIndex) throws IOException {
    long timestamp = getTimestamp(sampleIndex);
    LogRecord rec = xmlLogs.getRecordFor(timestamp / 1000000);
    if (rec != null) {
        long startTime = cpuSnapshot.getStartTime();
        long endTime = getTimestamp(getSamplesCount() - 1);
        long recTime = rec.getMillis() * 1000000;
        if (recTime > startTime && recTime < endTime) {
            if (rec != lastRecord) {
                Integer index = new Integer(sampleIndex+1);
                lastRecord = rec;
                recordsMap.put(index, rec);
                return index;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:IdeSnapshot.java

示例2: addRecord

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Take new record, update last timestamp of entity and emit it to all listeners.
 * @param record
 */
protected void addRecord(LogRecord record) {
    // handle records so I have consistent info.
    // All records are stored in the records
    //logRecords.add(record);

    // update log events according to info in record. In many cases nothing will happen.
    LogMessage logMessage = logEvents.updateLogMessages(record);
    if (logMessage != null) {
        emitNewLogMessage(logMessage);
    }

    LogEvent logEvent = logEvents.updateLogEvents(record);
    if (logEvent != null) {
        emitNewLogEvent(logEvent);
    }

    // update map events according to info in record. In many cases nothing will happen.
    mapEvents.update(record);

    long milis = record.getMillis();

    this.entity.setEndTime(milis);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:28,代码来源:TLLogRecorder.java

示例3: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Format the log record as follows:
 *
 *     Date Level Message ExceptionTrace
 *
 * @param       logRecord       The log record
 * @return                      The formatted string
 */
@Override
public String format(LogRecord logRecord) {
    Object[] arguments = new Object[4];
    arguments[0] = new Date(logRecord.getMillis());
    arguments[1] = logRecord.getLevel().getName();
    arguments[2] = logRecord.getMessage();
    Throwable exc = logRecord.getThrown();
    if (exc != null) {
        Writer result = new StringWriter();
        exc.printStackTrace(new PrintWriter(result));
        arguments[3] = result.toString();
    } else {
        arguments[3] = "";
    }
    return messageFormat.get().format(arguments);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:25,代码来源:BriefLogFormatter.java

示例4: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
@Override
public String format(LogRecord record) {
  Date date = new Date(record.getMillis());
  String msg =
      String.format(
          "%s %s %s [%s] %s\n",
          DATE_FORMAT.format(date),
          record.getLevel().toString().substring(0, 1),
          record.getLoggerName(),
          record.getSourceMethodName(),
          record.getMessage());

  Throwable e = record.getThrown();
  if (e != null) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    e.printStackTrace(new PrintStream(stream));
    msg += new String(stream.toByteArray(), UTF_8);
  }
  return msg;
}
 
开发者ID:google,项目名称:devicehub,代码行数:21,代码来源:HubLogger.java

示例5: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public String format( LogRecord rec) {
	int ii;
	StringBuffer outbuf = new StringBuffer(200);
	long tmval = rec.getMillis();
	if (timeType == DleseLogManager.LOG_UTCTIME) {
		// convert local time to UTC
		TimeZone tz = TimeZone.getDefault();
		tmval -= tz.getRawOffset();
	}
	outbuf.append( dateformat.format( new Date(tmval)));
	outbuf.append(" ");
	outbuf.append(rec.getLevel());
	outbuf.append(" ");
	String classname = rec.getSourceClassName();
	int ix = classname.lastIndexOf(".");
	if (ix >= 0 && ix < classname.length() - 1)
		classname = classname.substring( ix + 1);
	outbuf.append(classname);
	outbuf.append(".");
	outbuf.append(rec.getSourceMethodName());
	outbuf.append(" ");
	outbuf.append(rec.getMessage());
	outbuf.append("\n");
	Object[] parms = rec.getParameters();
	if (parms != null && parms.length > 0) {
		for (ii = 0; ii < parms.length; ii++) {
			outbuf.append("    parm ");
			outbuf.append(Integer.toString(ii));
			outbuf.append(": ");
			if (parms[ii] == null) outbuf.append("(null)");
			else outbuf.append( parms[ii].toString());
			outbuf.append("\n");
		}
	}
	return new String( outbuf);
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:37,代码来源:DebugLogger.java

示例6: buildParameters

import java.util.logging.LogRecord; //导入方法依赖的package包/类
private Object[] buildParameters(LogRecord record) {
    StackTraceElement frame = getCaller();

    Object[] arguments = new Object[otherPartsSize + 1];
    arguments[0] = new Long(record.getSequenceNumber());
    arguments[1] = new Date(record.getMillis());
    arguments[2] = record.getLoggerName();
    arguments[3] = record.getSourceClassName();
    arguments[4] = record.getSourceMethodName();
    if (frame != null) {
        arguments[5] = frame.getFileName();
        arguments[6] = frame.getLineNumber();
    } else {
        arguments[5] = "";
        arguments[6] = -1;
    }
    // LogRecord.getThreadID is not the actual thread ID.
    // arguments[7]=new Integer(record.getThreadID());
    arguments[7] = Thread.currentThread().getId();
    arguments[12] = Thread.currentThread().getName();

    // arguments[8]=record.getLevel().getLocalizedName();
    // this is faster, but not i18n
    arguments[8] = record.getLevel().getName();
    arguments[9] = new Integer(record.getLevel().intValue());
    arguments[11] = writeThrowable(arguments, record, 0);
    return arguments;
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:29,代码来源:DefaultFormatter.java

示例7: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Formats a given log record for logging.
 */
public String format(LogRecord record) {
	StringBuilder builder = new StringBuilder(1000);
	Date logTime = new Date(record.getMillis());
	builder.append(LOG_DATE_FORMAT.format(logTime));
	builder.append(" - ");
	builder.append("[").append(record.getSourceClassName());
	builder.append(".");
	builder.append(record.getSourceMethodName());
	Object[] params = record.getParameters();

	// we are in full control of this instance and we are passing
	// the line of the call from the source file as the first entry
	// in the parameter array
	if (params != null && params.length >= 1) {
		builder.append(":");
		builder.append(params[0]);
	}
	builder.append("] - ");
	builder.append("[").append(record.getLevel());
	builder.append("] - ");
	builder.append(formatMessage(record));
	if (record.getThrown() != null) {
		format(record.getThrown(), builder, 0);
	}
	builder.append("\n");
	return builder.toString();
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:31,代码来源:Logging.java

示例8: asSerializableLogRecord

import java.util.logging.LogRecord; //导入方法依赖的package包/类
private SerializableLogRecord asSerializableLogRecord(LogRecord record) {
    SerializableLogRecord serializableLogRecord = new SerializableLogRecord();
    serializableLogRecord.level = record.getLevel().toString();
    serializableLogRecord.millis = record.getMillis();
    serializableLogRecord.message = record.getMessage();
    serializableLogRecord.loggerName = record.getLoggerName();
    serializableLogRecord.permutationStrongName = GWT.getPermutationStrongName();
    serializableLogRecord.thrown = serializableThrowable(unwrap(record.getThrown()));
    return serializableLogRecord;
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:11,代码来源:RestfulRemoteLogHandler.java

示例9: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public String format(LogRecord record) {

            // Create a StringBuffer to contain the formatted record
            // start with the date.
            StringBuffer sb = new StringBuffer();

            sb.append("<font color=#ff0000>");

            // Get the date from the LogRecord and add it to the buffer
            Date date = new Date(record.getMillis());
            sb.append(date.toString());
            sb.append(" ");

            // get the name of the class
            sb.append(record.getSourceClassName());
            sb.append(" ");

            // get the name of the method
            sb.append(record.getSourceMethodName().replace("<", "[").replace(">", "]"));
            sb.append("\n");

            // Get the level name and add it to the buffer
            sb.append(record.getLevel().getName());
            sb.append(": ");

            // Get the formatted message (includes localization
            // and substitution of paramters) and add it to the buffer
            sb.append(formatMessage(record).replace("<", "[").replace(">", "]"));
            sb.append("\n");

            sb.append("</font>");

            return sb.toString();
        }
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:35,代码来源:CustomLogHandler.java

示例10: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
@Override
public String format(LogRecord record) {
    Date date = new Date(record.getMillis());
    return "[" + sdf.format(date) + " " + record.getLevel() + "] " + record.getMessage() + "\n";
}
 
开发者ID:pr0-soft,项目名称:pr0-stats,代码行数:6,代码来源:SimpleConsoleFormatter.java

示例11: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
@Override
public String format(LogRecord record) {
    Throwable t=record.getThrown();
    int level=record.getLevel().intValue();
    String name=record.getLoggerName();
    long time=record.getMillis();
    String message=formatMessage(record);


    if( name.indexOf('.') >= 0 )
        name = name.substring(name.lastIndexOf('.') + 1);

    // Use a string buffer for better performance
    StringBuilder buf = new StringBuilder();
    
    buf.append(time);
    
    // pad to 8 to make it more readable 
    for( int i=0; i<8-buf.length(); i++ ) { buf.append(" "); }
    
    //      Append a readable representation of the log level.
    switch(level) {
     case LOG_LEVEL_TRACE: buf.append(" T "); break;
     case LOG_LEVEL_DEBUG: buf.append(" D "); break;
     case LOG_LEVEL_INFO:  buf.append(" I ");  break;
     case LOG_LEVEL_WARN:  buf.append(" W ");  break;
     case LOG_LEVEL_ERROR: buf.append(" E "); break;
     //case : buf.append(" F "); break;
     default: buf.append("   ");
     }
     

    // Append the name of the log instance if so configured
    buf.append(name);
    buf.append(" ");

    // pad to 20 chars 
    for( int i=0; i<8-buf.length(); i++ ) { buf.append(" "); }
            
    // Append the message
    buf.append(message);
    
    // Append stack trace if not null
    if(t != null) {
        buf.append(LINE_SEP);
        
        java.io.StringWriter sw= new java.io.StringWriter(1024);
        java.io.PrintWriter pw= new java.io.PrintWriter(sw);
        t.printStackTrace(pw);
        pw.close();
        buf.append(sw.toString());
    }
    
    buf.append(LINE_SEP);
    // Print to the appropriate destination
    return buf.toString();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:58,代码来源:JdkLoggerFormatter.java

示例12: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public String format(LogRecord record) {
    Throwable t=record.getThrown();
    int level=record.getLevel().intValue();
    String name=record.getLoggerName();
    long time=record.getMillis();
    String message=formatMessage(record);

    
    if( name.indexOf(".") >= 0 ) 
        name = name.substring(name.lastIndexOf(".") + 1);

    // Use a string buffer for better performance
    StringBuffer buf = new StringBuffer();
    
    buf.append(time);
    buf.append(" ");
    
    // pad to 8 to make it more readable 
    for( int i=0; i<8-buf.length(); i++ ) { buf.append(" "); }
    
    //      Append a readable representation of the log level.
    switch(level) {
     case LOG_LEVEL_TRACE: buf.append(" T "); break;
     case LOG_LEVEL_DEBUG: buf.append(" D "); break;
     case LOG_LEVEL_INFO:  buf.append(" I ");  break;
     case LOG_LEVEL_WARN:  buf.append(" W ");  break;
     case LOG_LEVEL_ERROR: buf.append(" E "); break;
     //case : buf.append(" F "); break;
     default: buf.append("   ");
     }
     

    // Append the name of the log instance if so configured
    buf.append(name);
    
    // pad to 20 chars 
    for( int i=0; i<8-buf.length(); i++ ) { buf.append(" "); }
            
    // Append the message
    buf.append(message);
    
    // Append stack trace if not null
    if(t != null) {
        buf.append(" \n");
        
        java.io.StringWriter sw= new java.io.StringWriter(1024);
        java.io.PrintWriter pw= new java.io.PrintWriter(sw);
        t.printStackTrace(pw);
        pw.close();
        buf.append(sw.toString());
    }
    
    buf.append("\n");
    // Print to the appropriate destination
    return buf.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:JdkLoggerFormatter.java

示例13: test

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public static void test(Properties props) {
    Configuration conf = Configuration.apply(props);

    LogRecord record = new LogRecord(Level.INFO, "Test Name: {0}");
    record.setLoggerName("test");
    record.setParameters(new Object[] {conf.testName()});
    int nanos = record.getInstant().getNano() % NANOS_IN_MILLI;
    long millis = record.getMillis();
    // make sure we don't have leading zeros when printing below
    // the second precision
    if (millis % MILLIS_IN_SECOND < 100) millis = millis + 100;
    // make sure we some nanos - and make sure we don't have
    // trailing zeros
    if (nanos % 10 == 0) nanos = nanos + 7;

    record.setMillis(millis);
    setNanoAdjustment(record, nanos);
    final Instant instant = record.getInstant();
    if (nanos < 0) {
        throw new RuntimeException("Unexpected negative nano adjustment: "
                + getNanoAdjustment(record));
    }
    if (nanos >= NANOS_IN_MILLI) {
        throw new RuntimeException("Nano adjustment exceeds 1ms: "
                + getNanoAdjustment(record));
    }
    if (millis != record.getMillis()) {
        throw new RuntimeException("Unexpected millis: " + millis + " != "
                + record.getMillis());
    }
    if (millis != record.getInstant().toEpochMilli()) {
        throw new RuntimeException("Unexpected millis: "
                + record.getInstant().toEpochMilli());
    }
    long expectedNanos = (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + nanos;
    assertEquals(expectedNanos, instant.getNano(), "Instant.getNano()");

    XMLFormatter formatter = new XMLFormatter();
    testMatching(formatter, record, instant, expectedNanos, conf.useInstant(formatter));

    XMLFormatter custom = new CustomXMLFormatter();
    testMatching(custom, record, instant, expectedNanos, conf.useInstant(custom));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:XmlFormatterNanos.java

示例14: test

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Serializes a log record, then deserializes it and check that both
 * records match.
 * @param record the log record to serialize & deserialize.
 * @param hasExceedingNanos whether the record has a nano adjustment whose
 *            value exceeds 1ms.
 * @throws IOException Unexpected.
 * @throws ClassNotFoundException  Unexpected.
 */
public static void test(LogRecord record, boolean hasExceedingNanos)
        throws IOException, ClassNotFoundException {

    // Format the given logRecord using the SimpleFormatter
    SimpleFormatter formatter = new SimpleFormatter();
    String str = formatter.format(record);

    // Serialize the given LogRecord
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(record);
    oos.flush();
    oos.close();

    // First checks that the log record can be deserialized
    final ByteArrayInputStream bais =
            new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream ois = new ObjectInputStream(bais);
    final LogRecord record2 = (LogRecord)ois.readObject();

    assertEquals(record.getMillis(), record2.getMillis(), "getMillis()");
    assertEquals(record.getInstant().getEpochSecond(),
            record2.getInstant().getEpochSecond(),
            "getInstant().getEpochSecond()");
    assertEquals(record.getInstant().getNano(),
            record2.getInstant().getNano(),
            "getInstant().getNano()");
    assertEquals(record.getInstant().toEpochMilli(),
            record2.getInstant().toEpochMilli(),
            "getInstant().toEpochMilli()");
    long millis = record.getMillis();
    millis = hasExceedingNanos
            ? Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
                    (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI
                    + record.getInstant().getNano() % NANOS_IN_MILLI).toEpochMilli()
            : millis;
    assertEquals(millis, record.getInstant().toEpochMilli(),
            "getMillis()/getInstant().toEpochMilli()");
    millis = record2.getMillis();
    millis = hasExceedingNanos
            ? Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
                    (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI
                    + record2.getInstant().getNano() % NANOS_IN_MILLI).toEpochMilli()
            : millis;
    assertEquals(millis, record2.getInstant().toEpochMilli(),
            "getMillis()/getInstant().toEpochMilli()");
    long nanos = nanoInSecondFromEpochMilli(record.getMillis())
            + record.getInstant().getNano() % NANOS_IN_MILLI;
    assertEquals(nanos, record.getInstant().getNano(),
            "nanoInSecondFromEpochMilli(record.getMillis())"
            + " + record.getInstant().getNano() % NANOS_IN_MILLI /getInstant().getNano()");
    nanos = nanoInSecondFromEpochMilli(record2.getMillis())
            + record2.getInstant().getNano() % NANOS_IN_MILLI;
    assertEquals(nanos, record2.getInstant().getNano(),
            "nanoInSecondFromEpochMilli(record2.getMillis())"
            + " + record2.getInstant().getNano() % NANOS_IN_MILLI /getInstant().getNano()");

    // Format the deserialized LogRecord using the SimpleFormatter, and
    // check that the string representation obtained matches the string
    // representation of the original LogRecord
    String str2 = formatter.format(record2);
    if (!str.equals(str2))
        throw new RuntimeException("Unexpected values in deserialized object:"
            + "\n\tExpected:  " + str
            + "\n\tRetrieved: "+str);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:LogRecordWithNanosAPI.java

示例15: format

import java.util.logging.LogRecord; //导入方法依赖的package包/类
@Override
public String format(LogRecord record) {
	Throwable t = record.getThrown();
	int level = record.getLevel().intValue();
	String name = record.getLoggerName();
	long time = record.getMillis();
	String message = formatMessage(record);

	if (name.indexOf('.') >= 0)
		name = name.substring(name.lastIndexOf('.') + 1);

	// Use a string buffer for better performance
	StringBuilder buf = new StringBuilder();

	buf.append(time);

	// pad to 8 to make it more readable
	for (int i = 0; i < 8 - buf.length(); i++) {
		buf.append(" ");
	}

	// Append a readable representation of the log level.
	switch (level) {
	case LOG_LEVEL_TRACE:
		buf.append(" T ");
		break;
	case LOG_LEVEL_DEBUG:
		buf.append(" D ");
		break;
	case LOG_LEVEL_INFO:
		buf.append(" I ");
		break;
	case LOG_LEVEL_WARN:
		buf.append(" W ");
		break;
	case LOG_LEVEL_ERROR:
		buf.append(" E ");
		break;
	// case : buf.append(" F "); break;
	default:
		buf.append("   ");
	}

	// Append the name of the log instance if so configured
	buf.append(name);
	buf.append(" ");

	// pad to 20 chars
	for (int i = 0; i < 8 - buf.length(); i++) {
		buf.append(" ");
	}

	// Append the message
	buf.append(message);

	// Append stack trace if not null
	if (t != null) {
		buf.append(LINE_SEP);

		java.io.StringWriter sw = new java.io.StringWriter(1024);
		java.io.PrintWriter pw = new java.io.PrintWriter(sw);
		t.printStackTrace(pw);
		pw.close();
		buf.append(sw.toString());
	}

	buf.append(LINE_SEP);
	// Print to the appropriate destination
	return buf.toString();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:71,代码来源:JdkLoggerFormatter.java


注:本文中的java.util.logging.LogRecord.getMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。