Java Code Examples for java.util.logging.LogRecord#setInstant()
The following examples show how to use
java.util.logging.LogRecord#setInstant() .
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: VespaFormatterTestCase.java From vespa with Apache License 2.0 | 6 votes |
/** * test that {0} etc is replaced properly */ @Test public void testTextFormatting () { VespaFormatter formatter = new VespaFormatter(serviceName, app); LogRecord testRecord = new LogRecord(Level.INFO, "this {1} is {0} test"); testRecord.setInstant(Instant.ofEpochMilli(1098709021843L)); testRecord.setThreadID(123); testRecord.setLoggerName("org.foo"); Object[] params = { "a small", "message" }; testRecord.setParameters(params); String expected = "1098709021.843000\t" + hostname + "\t" + pid + "/123" + "\t" + "serviceName\t" + app + ".org.foo\t" + "info\t" + "this message is a small test\n"; assertEquals(expected, formatter.format(testRecord)); }
Example 2
Source File: LogSetupTestCase.java From vespa with Apache License 2.0 | 5 votes |
@Before public void setUp() { System.setProperty("config.id", "my-test-config-id"); System.setProperty("vespa.log.target", "file:test3"); zookeeperLogRecord = new LogRecord(Level.WARNING, "zookeeper log record"); zookeeperLogRecord.setLoggerName("org.apache.zookeeper.server.NIOServerCnxn"); zookeeperLogRecord.setInstant(Instant.ofEpochMilli(1107011348029L)); curatorLogRecord = new LogRecord(Level.WARNING, "curator log record"); curatorLogRecord.setLoggerName("org.apache.curator.utils.DefaultTracerDriver"); curatorLogRecord.setInstant(Instant.ofEpochMilli(1107011348029L)); hostname = Util.getHostName(); pid = Util.getPID(); zookeeperLogRecordString = "1107011348.029000\t" + hostname + "\t" + pid + "/" + zookeeperLogRecord.getThreadID() + "\t-\t.org.apache.zookeeper.server.NIOServerCnxn" + "\twarning\tzookeeper log record"; zookeeperLogRecordError = new LogRecord(Level.SEVERE, "zookeeper error"); zookeeperLogRecordError.setLoggerName("org.apache.zookeeper.server.NIOServerCnxn"); zookeeperLogRecordError.setInstant(Instant.ofEpochMilli(1107011348029L)); curatorLogRecordError = new LogRecord(Level.SEVERE, "curator log record"); curatorLogRecordError.setLoggerName("org.apache.curator.utils.DefaultTracerDriver"); curatorLogRecordError.setInstant(Instant.ofEpochMilli(1107011348029L)); notzookeeperLogRecord = new LogRecord(Level.WARNING, "not zookeeper log record"); notzookeeperLogRecord.setLoggerName("org.apache.foo.Bar"); notzookeeperLogRecord.setInstant(Instant.ofEpochMilli(1107011348029L)); }
Example 3
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 4
Source File: XmlFormatterNanos.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void setNanoAdjustment(LogRecord record, int nanos) { record.setInstant(Instant.ofEpochSecond(record.getInstant().getEpochSecond(), (record.getInstant().getNano() / NANOS_IN_MILLI) * NANOS_IN_MILLI + nanos)); }
Example 5
Source File: SimpleFormatterNanos.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void setNanoAdjustment(LogRecord record, int nanos) { record.setInstant(Instant.ofEpochSecond(record.getInstant().getEpochSecond(), (record.getInstant().getNano() / NANOS_IN_MILLI) * NANOS_IN_MILLI + nanos)); }
Example 6
Source File: VespaFormatterTestCase.java From vespa with Apache License 2.0 | 4 votes |
@Before public void setUp () { hostname = Util.getHostName(); pid = Util.getPID(); testRecord1 = new LogRecord(Level.INFO, "this is a test"); testRecord1.setInstant(Instant.ofEpochMilli(1098709021843L)); testRecord1.setThreadID(123); expected1 = "1098709021.843000\t" + hostname + "\t" + pid + "/123" + "\t" + "serviceName\t" + "tst\t" + "info\t" + "this is a test\n"; expected2 = "1098709021.843000\t" + hostname + "\t" + pid + "/123" + "\t" + "serviceName\t" + "-\t" + "info\t" + "this is a test\n"; testRecord2 = new LogRecord(Level.INFO, "this is a test"); testRecord2.setInstant(Instant.ofEpochMilli(1098709021843L)); testRecord2.setThreadID(123); testRecord2.setLoggerName("org.foo"); expected3 = "1098709021.843000\t" + hostname + "\t" + pid + "/123" + "\t" + "serviceName\t" + ".org.foo\t" + "info\t" + "this is a test\n"; expected4 = "1098709021.843000\t" + hostname + "\t" + pid + "/123" + "\t" + "serviceName\t" + "tst.org.foo\t" + "info\t" + "this is a test\n"; }
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")); }