java.util.logging.LogRecord#getMessage ( )源码实例Demo

下面列出了java.util.logging.LogRecord#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RipplePower   文件: BriefLogFormatter.java
@Override
public String format(LogRecord logRecord) {
	Object[] arguments = new Object[6];
	arguments[0] = logRecord.getLevel().getName();
	String fullClassName = logRecord.getSourceClassName();
	int lastDot = fullClassName.lastIndexOf('.');
	String className = fullClassName.substring(lastDot + 1);
	arguments[1] = className;
	arguments[2] = logRecord.getSourceMethodName();
	arguments[3] = new Date(logRecord.getMillis());
	arguments[4] = logRecord.getMessage();
	if (logRecord.getThrown() != null) {
		Writer result = new StringWriter();
		logRecord.getThrown().printStackTrace(new PrintWriter(result));
		arguments[5] = result.toString();
	} else {
		arguments[5] = "";
	}

	return messageFormat.format(arguments);
}
 
源代码2 项目: netbeans   文件: Exceptions.java
private void logRecords(Appendable a) {
    List<LogRecord> r = records;
    if (r == null) {
        return;
    }
    try {

        for (LogRecord log : r) {
            if (log.getMessage() != null) {
                a.append(log.getMessage()).append("\n");;
            }
            if (log.getThrown() != null) {
                StringWriter w = new StringWriter();
                log.getThrown().printStackTrace(new PrintWriter(w));
                a.append(w.toString()).append("\n");
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
源代码3 项目: component-runtime   文件: EnvironmentSetup.java
@Override
public String format(final LogRecord record) {
    final ZonedDateTime zdt =
            ZonedDateTime.ofInstant(Instant.ofEpochMilli(record.getMillis()), zone).withZoneSameInstant(utc);
    final String date = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zdt);
    final String thread =
            record.getThreadID() == Thread.currentThread().getId() ? Thread.currentThread().getName()
                    : ("thread-" + record.getThreadID());
    final String base = '[' + date + "][" + thread + "][" + record.getLevel().getName() + "]["
            + record.getLoggerName() + "] " + record.getMessage() + System.lineSeparator();
    final String throwable;
    if (record.getThrown() != null) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw);
        pw.println();
        record.getThrown().printStackTrace(pw);
        pw.close();
        throwable = sw.toString();
    } else {
        throwable = null;
    }
    return base + (throwable == null ? "" : throwable);
}
 
源代码4 项目: netbeans   文件: JFXApplicationClassChooserTest.java
@Override
public synchronized void publish(LogRecord record) {
    final String message = record.getMessage();
    if (JFXApplicationClassChooser.LOG_INIT.equals(message)) {
        callInterceptor(0);
    } else if (JFXApplicationClassChooser.LOG_MAIN_CLASSES.equals(message)) {
        callInterceptor(1);
        final String[] result = ((Set<String>)record.getParameters()[0]).toArray(new String[0]);
        final boolean scan = (Boolean) record.getParameters()[1];
        final String[] expected = mainClasses.removeFirst();
        Arrays.sort(result);
        Arrays.sort(expected);
        final boolean last = mainClasses.isEmpty();
        if (last == scan) {
            failure = "Expected " + (!last) + ", Result: " + scan;  //NOI18N
            notifyAll();
        } else if (!Arrays.equals(expected, result)) {
            failure = "Expected " + Arrays.toString(expected) + ", Result: " + Arrays.toString(result); //NOI18N
            notifyAll();
        } else if (last) {
            notifyAll();
        }                
    }
}
 
源代码5 项目: vespa   文件: RecentLogFilter.java
public boolean isLoggable(LogRecord record) {
    String msg = record.getMessage();
    if (msg != null && recent.contains(msg)) {
        return false;  // duplicate
    } else {
        recent.addLast(msg);
        if (recent.size() > maxMessages) {
            recent.removeFirst();
        }
        return true;   // new message
    }
}
 
源代码6 项目: ThingML-Tradfri   文件: LoggingPanel.java
@Override
public void publish(LogRecord record) {
    final String msg = "[" + sdf.format(new Date(record.getMillis())) + "] [" +record.getLevel().getName() + "] " + record.getMessage() + "\n" ;
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          appendLog(msg);
        }
      });
}
 
源代码7 项目: jdk8u-dev-jdk   文件: TestLogrbResourceBundle.java
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
源代码8 项目: triplea   文件: ErrorMessageFormatter.java
private static String logMessageAndExceptionMessage(final LogRecord logRecord) {
  checkArgument(logRecord.getThrown().getMessage() != null);
  checkArgument(logRecord.getMessage() != null);
  checkArgument(!logRecord.getThrown().getMessage().equals(logRecord.getMessage()));

  return logRecord.getMessage()
      + BREAK
      + simpleName(logRecord)
      + ": "
      + logRecord.getThrown().getMessage();
}
 
@Override
public void publish(LogRecord record) {
    if (Boolean.getBoolean("counting.off")) {
        return;
    }
    final String m = record.getMessage();
    if (m != null && m.startsWith("Initialize data")) {
        Object[] params = record.getParameters();
        assertNotNull("There are parameters", params);
        assertEquals("There is just one parameter: " + Arrays.toString(params), 1, params.length);
        if (params[0] == null) {
            // fixed modules are OK
            return;
        }
        if (isPlatformOrIde((File)params[0])) {
            return;
        }
        
        String prev = System.getProperty("manifestParsing");
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        if (prev != null) {
            pw.append(prev).append("\n");
        }
        final String msg = m + ": " + params[0];
        if (Boolean.getBoolean("no.stacks")) {
            pw.print(msg);
        } else { 
            new Exception(msg).printStackTrace(pw);
        }
        pw.flush();
        System.setProperty("manifestParsing", sw.toString());
    }
}
 
源代码10 项目: openjdk-jdk9   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码11 项目: netbeans   文件: RunWhenScanFinishedSupportTest.java
@Override
public void publish(LogRecord record) {            
    final String message = record.getMessage();
    final Object param = record.getParameters()[0];
    for (Iterator<Pair<Pair<String, Object>, CountDownLatch>> it = condition.iterator(); it.hasNext();) {
        final Pair<Pair<String,Object>,CountDownLatch> cnd = it.next();
        if (cnd != null && cnd.first().first().equals(message) && cnd.first().second().equals(param)) {
            //System.out.println("GOT: " + cnd.first.first + " " + cnd.first.second);
            it.remove();
            cnd.second().countDown();
            break;
        }
    }
}
 
源代码12 项目: QuickShop-Reremake   文件: LogFormat.java
@Override
public String format(LogRecord record) {
    String text = "[" + new SimpleDateFormat("HH:mm:ss").format(new Date(record.getMillis()));
    Level level = record.getLevel();

    if (level == Level.WARNING) {
        text += " WARNING]";
    } else if (level == Level.SEVERE) {
        text += " SEVERE]";
    } else {
        text += " INFO]";
    }

    text += " " + record.getMessage();
    text += "\r\n";

    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter stringWriter = new StringWriter();
        thrown.printStackTrace(new PrintWriter(stringWriter));
        text += stringWriter;
    }

    text = text.replaceAll("(\\u001b\\[\\d{1,3}(?:;\\d+)*m|(?:\\u001b\\[m)*)", "");
    // text = Colorizer.stripColors(text);

    return text;
}
 
源代码13 项目: jdk8u-jdk   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码14 项目: JWebAssembly   文件: JWebAssembly.java
@Override
public String format( LogRecord record ) {
    String msg = record.getMessage() + '\n';
    if( record.getThrown() != null ) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter( sw );
        record.getThrown().printStackTrace( pw );
        pw.close();
        msg += sw.toString();
    }
    return msg;
}
 
源代码15 项目: openjdk-jdk8u   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码16 项目: netbeans   文件: MimePathLookupTest.java
@Override
public void publish(LogRecord record) {
    final String message = record.getMessage();
    if (message.startsWith("Rebuilding MimeLookup for") && Thread.currentThread().getName().equals("Thread 1")) {
        try {
            // System.out.println("Publish enter");
            barrier.await();
            // System.out.println("Publish waiting");
            Thread.sleep(5000); // Give the other thread a chance to deadlock
            // System.out.println("Publish exit");
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
源代码17 项目: netbeans   文件: RepositoryUpdaterTest.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    if (type == Type.BATCH) {
        if ("scanBinary".equals(msg)) {
            @SuppressWarnings("unchecked")
            Set<URL> b = (Set<URL>) record.getParameters()[0];
            binaries = b;
            latch.countDown();
        }
        else if ("scanSources".equals(msg)) {
            @SuppressWarnings("unchecked")
            List<URL> s =(List<URL>) record.getParameters()[0];
            sources = s;
            latch.countDown();
        }
    } else if (type == Type.DELETE) {
        if ("delete".equals(msg)) {
            latch.countDown();
        }
    } else if (type == Type.FILELIST) {
        if ("filelist".equals(msg)) {
            latch.countDown();
        }
    } else if (type == Type.ROOTS_WORK_FINISHED) {
        if ("RootsWork-finished".equals(msg)) { //NOI18N
            latch.countDown();
        }
    } else if (type == Type.BINARY) {
        if ("binary".equals(msg)) { //NOI18N
            latch.countDown();
        }
    }
}
 
源代码18 项目: netbeans   文件: MIMEResolverImplTest.java
/**
 * Bug 240518 - org.openide.filesystems.FileAlreadyLockedException:
 * Services/MIMEResolver/user-defined-mime-resolver.xml.
 *
 * @throws InterruptedException
 */
public void testStoreUserDefinedResolver() throws InterruptedException {
    final Logger mimeResLog = Logger.getLogger(
            MIMEResolverImpl.class.getName());
    final Map<String, Set<String>> mimeToExtensions
            = new HashMap<String, Set<String>>();
    final Throwable[] throwable = new Throwable[1];
    mimeToExtensions.put("text/plan", Collections.singleton("log"));

    Runnable r = new Runnable() {
        @Override
        public void run() {
            MIMEResolverImpl.storeUserDefinedResolver(mimeToExtensions);
        }
    };

    Handler h = new Handler() {

        @Override
        public void publish(LogRecord record) {
            String msg = record.getMessage();
            if (msg != null && msg.startsWith("Cannot delete resolver ")) {
                throwable[0] = record.getThrown();
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };

    mimeResLog.addHandler(h);
    try {
        // run now to initialize the file
        r.run();

        // run twice in parallel.
        for (int i = 0; i < 10; i++) {
            Thread t1 = new Thread(r, "T1");
            Thread t2 = new Thread(r, "T2");
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            assertNull("No error should occur", throwable[0]);
        }
    } finally {
        mimeResLog.removeHandler(h);
    }
}
 
源代码19 项目: vespa   文件: LogFormatter.java
@Override
public String format(LogRecord record) {
    return record.getMillis() + " " + record.getLevel() + " "
            + record.getLoggerName().substring(record.getLoggerName().lastIndexOf('.') + 1) + " " + record.getMessage() + "\n";
}
 
源代码20 项目: binnavi   文件: NaviLogFormatter.java
@Override
public synchronized String format(final LogRecord record) {
  return record.getLevel() + ": " + record.getMessage() + "\n";
}