當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。