Java Code Examples for java.util.logging.LogRecord#setSequenceNumber()
The following examples show how to use
java.util.logging.LogRecord#setSequenceNumber() .
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: LogAdapter.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("deprecation") // setMillis is deprecated in JDK 9 protected Object writeReplace() { LogRecord serialized = new LogRecord(getLevel(), getMessage()); serialized.setLoggerName(getLoggerName()); serialized.setResourceBundle(getResourceBundle()); serialized.setResourceBundleName(getResourceBundleName()); serialized.setSourceClassName(getSourceClassName()); serialized.setSourceMethodName(getSourceMethodName()); serialized.setSequenceNumber(getSequenceNumber()); serialized.setParameters(getParameters()); serialized.setThreadID(getThreadID()); serialized.setMillis(getMillis()); serialized.setThrown(getThrown()); return serialized; }
Example 2
Source File: LogAdapter.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("deprecation") // setMillis is deprecated in JDK 9 protected Object writeReplace() { LogRecord serialized = new LogRecord(getLevel(), getMessage()); serialized.setLoggerName(getLoggerName()); serialized.setResourceBundle(getResourceBundle()); serialized.setResourceBundleName(getResourceBundleName()); serialized.setSourceClassName(getSourceClassName()); serialized.setSourceMethodName(getSourceMethodName()); serialized.setSequenceNumber(getSequenceNumber()); serialized.setParameters(getParameters()); serialized.setThreadID(getThreadID()); serialized.setMillis(getMillis()); serialized.setThrown(getThrown()); return serialized; }
Example 3
Source File: LogFactory.java From turbo-rpc with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") // setMillis is deprecated in JDK 9 protected Object writeReplace() { LogRecord serialized = new LogRecord(getLevel(), getMessage()); serialized.setLoggerName(getLoggerName()); serialized.setResourceBundle(getResourceBundle()); serialized.setResourceBundleName(getResourceBundleName()); serialized.setSourceClassName(getSourceClassName()); serialized.setSourceMethodName(getSourceMethodName()); serialized.setSequenceNumber(getSequenceNumber()); serialized.setParameters(getParameters()); serialized.setThreadID(getThreadID()); serialized.setMillis(getMillis()); serialized.setThrown(getThrown()); return serialized; }
Example 4
Source File: TestRunnerHandlerTest.java From vespa with Apache License 2.0 | 5 votes |
private static LogRecord createRecord(Exception exception) { LogRecord record = new LogRecord(Level.INFO, "Hello."); record.setSequenceNumber(1); record.setInstant(Instant.ofEpochMilli(2)); record.setThrown(exception); return record; }
Example 5
Source File: LogRecords.java From netbeans with Apache License 2.0 | 4 votes |
public void endElement(String uri, String localName, String qName) throws SAXException { if (current != null) { String v = chars.toString(); values.put(current, v); if (current == Elem.PARAM) { if (params == null) { params = new ArrayList<String>(); } params.add(v); if (params.size() > 1500) { LOG.severe("Too long params when reading a record. Deleting few. Msg: " + Elem.MESSAGE.parse(values)); // NOI18N for (String p : params) { LOG.fine(p); } params.clear(); } } } current = null; chars = new StringBuilder(); if (currentEx != null && currentEx.values != null) { if ("frame".equals(qName)) { // NOI18N String line = Elem.LINE.parse(values); StackTraceElement elem = new StackTraceElement( Elem.CLASS.parse(values), Elem.METHOD.parse(values), Elem.FILE.parse(values), line == null ? -1 : Integer.parseInt(line) ); currentEx.trace.add(elem); values.remove(Elem.CLASS); values.remove(Elem.METHOD); values.remove(Elem.LINE); } if ("exception".equals(qName)) { currentEx.message = values.get(Elem.MESSAGE); String more = values.get(Elem.MORE); if (more != null) currentEx.more = Integer.parseInt(more); if (exceptions == null){ exceptions = new ArrayDeque<FakeException>(); } exceptions.add(currentEx); values = currentEx.values; currentEx = null; } return; } if ("record".equals(qName)) { // NOI18N String millis = Elem.MILLIS.parse(values); String seq = Elem.SEQUENCE.parse(values); String lev = Elem.LEVEL.parse(values); String thread = Elem.THREAD.parse(values); String msg = Elem.MESSAGE.parse(values); String key = Elem.KEY.parse(values); String catalog = Elem.CATALOG.parse(values); if (lev != null) { LogRecord r = new LogRecord(parseLevel(lev), key != null && catalog != null ? key : msg); try { r.setThreadID(parseInt(thread)); } catch (NumberFormatException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex); } r.setSequenceNumber(parseLong(seq)); r.setMillis(parseLong(millis)); r.setResourceBundleName(key); if (catalog != null && key != null) { r.setResourceBundleName(catalog); if (!"<null>".equals(catalog)) { // NOI18N try { ResourceBundle b = NbBundle.getBundle(catalog); b.getObject(key); // ok, the key is there r.setResourceBundle(b); } catch (MissingResourceException e) { LOG.log(Level.CONFIG, "Cannot find resource bundle {0} for key {1}", new Object[] { catalog, key }); r.setResourceBundle(new FakeBundle(key, msg)); } } else { LOG.log(Level.CONFIG, "Cannot find resource bundle <null> for key {1}", key); } } if (params != null) { r.setParameters(params.toArray()); } if (exceptions != null) { r.setThrown(createThrown(null)); // exceptions = null; should be empty after poll } callback.publish(r); } currentEx = null; params = null; values.clear(); } }
Example 6
Source File: LogRecords.java From visualvm with GNU General Public License v2.0 | 4 votes |
public void endElement(String uri, String localName, String qName) throws SAXException { if (current != null) { String v = chars.toString(); values.put(current, v); if (current == Elem.PARAM) { if (params == null) { params = new ArrayList<String>(); } params.add(v); if (params.size() > 1500) { LOG.severe("Too long params when reading a record. Deleting few. Msg: " + Elem.MESSAGE.parse(values)); // NOI18N for (String p : params) { LOG.fine(p); } params.clear(); } } } current = null; chars = new StringBuilder(); if (currentEx != null && currentEx.values != null) { if ("frame".equals(qName)) { // NOI18N String line = Elem.LINE.parse(values); StackTraceElement elem = new StackTraceElement( Elem.CLASS.parse(values), Elem.METHOD.parse(values), Elem.FILE.parse(values), line == null ? -1 : Integer.parseInt(line) ); currentEx.trace.add(elem); values.remove(Elem.CLASS); values.remove(Elem.METHOD); values.remove(Elem.LINE); } if ("exception".equals(qName)) { currentEx.message = values.get(Elem.MESSAGE); String more = values.get(Elem.MORE); if (more != null) currentEx.more = Integer.parseInt(more); if (exceptions == null){ exceptions = new ArrayDeque<FakeException>(); } exceptions.add(currentEx); values = currentEx.values; currentEx = null; } return; } if ("record".equals(qName)) { // NOI18N String millis = Elem.MILLIS.parse(values); String seq = Elem.SEQUENCE.parse(values); String lev = Elem.LEVEL.parse(values); String thread = Elem.THREAD.parse(values); String msg = Elem.MESSAGE.parse(values); String key = Elem.KEY.parse(values); String catalog = Elem.CATALOG.parse(values); if (lev != null) { LogRecord r = new LogRecord(parseLevel(lev), key != null && catalog != null ? key : msg); try { r.setThreadID(parseInt(thread)); } catch (NumberFormatException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex); } r.setSequenceNumber(parseLong(seq)); r.setMillis(parseLong(millis)); r.setResourceBundleName(key); if (catalog != null && key != null) { r.setResourceBundleName(catalog); if (!"<null>".equals(catalog)) { // NOI18N try { ResourceBundle b = NbBundle.getBundle(catalog); b.getObject(key); // ok, the key is there r.setResourceBundle(b); } catch (MissingResourceException e) { LOG.log(Level.CONFIG, "Cannot find resource bundle {0} for key {1}", new Object[] { catalog, key }); r.setResourceBundle(new FakeBundle(key, msg)); } } else { LOG.log(Level.CONFIG, "Cannot find resource bundle <null> for key {1}", key); } } if (params != null) { r.setParameters(params.toArray()); } if (exceptions != null) { r.setThrown(createThrown(null)); // exceptions = null; should be empty after poll } callback.publish(r); } currentEx = null; params = null; values.clear(); } }
Example 7
Source File: OsgiLogHandlerTestCase.java From vespa with Apache License 2.0 | 4 votes |
@Test public void requireThatJdk14PropertiesAreAvailableThroughServiceReference() { MyLogService logService = new MyLogService(); Logger log = newLogger(logService); LogRecord record = new LogRecord(Level.INFO, "message"); record.setLoggerName("loggerName"); record.setInstant(Instant.ofEpochMilli(69)); Object[] parameters = new Object[0]; record.setParameters(parameters); ResourceBundle resouceBundle = new MyResourceBundle(); record.setResourceBundle(resouceBundle); record.setResourceBundleName("resourceBundleName"); record.setSequenceNumber(69); record.setSourceClassName("sourceClassName"); record.setSourceMethodName("sourceMethodName"); record.setThreadID(69); Throwable thrown = new Throwable(); record.setThrown(thrown); log.log(record); ServiceReference<?> ref = logService.lastServiceReference; assertNotNull(ref); assertTrue(Arrays.equals(new String[] { "LEVEL", "LOGGER_NAME", "MESSAGE", "MILLIS", "PARAMETERS", "RESOURCE_BUNDLE", "RESOURCE_BUNDLE_NAME", "SEQUENCE_NUMBER", "SOURCE_CLASS_NAME", "SOURCE_METHOD_NAME", "THREAD_ID", "THROWN" }, ref.getPropertyKeys())); assertEquals(Level.INFO, ref.getProperty("LEVEL")); assertEquals("loggerName", ref.getProperty("LOGGER_NAME")); assertEquals("message", ref.getProperty("MESSAGE")); assertEquals(69L, ref.getProperty("MILLIS")); assertSame(parameters, ref.getProperty("PARAMETERS")); assertSame(resouceBundle, ref.getProperty("RESOURCE_BUNDLE")); assertEquals("resourceBundleName", ref.getProperty("RESOURCE_BUNDLE_NAME")); assertEquals(69L, ref.getProperty("SEQUENCE_NUMBER")); assertEquals("sourceClassName", ref.getProperty("SOURCE_CLASS_NAME")); assertEquals("sourceMethodName", ref.getProperty("SOURCE_METHOD_NAME")); assertEquals(69, ref.getProperty("THREAD_ID")); assertSame(thrown, ref.getProperty("THROWN")); assertNull(ref.getProperty("unknown")); }