Java Code Examples for java.util.logging.LogRecord#getMessage()

The following examples show how to use java.util.logging.LogRecord#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BriefLogFormatter.java    From RipplePower with Apache License 2.0 7 votes vote down vote up
@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);
}
 
Example 2
Source File: JFXApplicationClassChooserTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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();
        }                
    }
}
 
Example 3
Source File: EnvironmentSetup.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: Exceptions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 5
Source File: TestLogrbResourceBundle.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
Example 6
Source File: ErrorMessageFormatter.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: LoggingPanel.java    From ThingML-Tradfri with Apache License 2.0 5 votes vote down vote up
@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);
        }
      });
}
 
Example 8
Source File: CachingPreventsLoadingOfModuleManifestsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example 9
Source File: TestLogHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: RunWhenScanFinishedSupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 11
Source File: RecentLogFilter.java    From vespa with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example 12
Source File: LogFormat.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: TestLogHandler.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 14
Source File: JWebAssembly.java    From JWebAssembly with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 15
Source File: TestLogHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 16
Source File: MimePathLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 17
Source File: RepositoryUpdaterTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 18
Source File: LogFormatter.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public String format(LogRecord record) {
    return record.getMillis() + " " + record.getLevel() + " "
            + record.getLoggerName().substring(record.getLoggerName().lastIndexOf('.') + 1) + " " + record.getMessage() + "\n";
}
 
Example 19
Source File: NaviLogFormatter.java    From binnavi with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized String format(final LogRecord record) {
  return record.getLevel() + ": " + record.getMessage() + "\n";
}
 
Example 20
Source File: MIMEResolverImplTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}