com.google.appengine.api.log.RequestLogs Java Examples
The following examples show how to use
com.google.appengine.api.log.RequestLogs.
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: LoggingTest.java From appengine-tck with Apache License 2.0 | 6 votes |
public RequestLogs getCurrentRequestLogs() { LogQuery logQuery = new LogQuery() .includeAppLogs(true) .includeIncomplete(true) .startTimeMillis(System.currentTimeMillis() - 20000); for (RequestLogs requestLogs : LogServiceFactory.getLogService().fetch(logQuery)) { if (requestLogs.getRequestId().equals(getCurrentRequestId())) { return requestLogs; } } fail("Could not find RequestLogs for current request"); return null; // not sure, why the following code throws LogServiceException: An error occurred retrieving logs from storage. // LogQuery logQuery = new LogQuery() // .includeAppLogs(true) // .requestIds(Collections.singletonList(getCurrentRequestId())); // Iterable<RequestLogs> iterable = LogServiceFactory.getLogService().fetch(logQuery); // assertTrue("Could not find RequestLogs for current request", iterable.iterator().hasNext()); // return iterable.iterator().next(); }
Example #2
Source File: LoggingTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testLogLinesAreReturnedInSameOrderAsTheyAreLogged() { String logMark = getTimeStampRandom(); String msg1 = "msg 1 " + logMark; String msg2 = "msg 2 " + logMark; log.log(Level.INFO, msg1); log.log(Level.INFO, msg2); flush(log); sync(15000); RequestLogs requestLogs = getCurrentRequestLogs(); Integer msg1Index = null; Integer msg2Index = null; int i = 0; for (AppLogLine appLogLine : requestLogs.getAppLogLines()) { if (appLogLine.getLogMessage().contains(msg1)) { msg1Index = i; } else if (appLogLine.getLogMessage().contains(msg2)) { msg2Index = i; } i++; } assertNotNull("1st log message not found in appLogLines", msg1Index); assertNotNull("2nd log message not found in appLogLines", msg2Index); assertTrue("Expected first logged message to come before second logged message", msg1Index < msg2Index); }
Example #3
Source File: LoggingServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); if (req.getParameter("printLogs") != null) { LogService ls = LogServiceFactory.getLogService(); LogQuery query = withIncludeAppLogs(true).minLogLevel(LogService.LogLevel.FATAL); for (RequestLogs logs : ls.fetch(query)) { for (AppLogLine logLine : logs.getAppLogLines()) { if (logLine.getLogLevel().equals(LogService.LogLevel.FATAL)) { resp.getWriter().println(logLine); } } } } else { Logger logger = Logger.getLogger("com.foo"); resp.getWriter().println(logger.getLevel()); Logger logger2 = Logger.getLogger("com.foo.bar"); resp.getWriter().println(logger2.getLevel()); resp.getWriter().println(configRan); logger2.severe("not null"); logger2.severe((String)null); } }
Example #4
Source File: LogQueryTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test @InSequence(20) public void testRequestIds() throws Exception { LogService service = LogServiceFactory.getLogService(); LogQuery logQuery = new LogQuery().requestIds(Arrays.asList(request1Id, request2Id)); Iterator<RequestLogs> iterator = service.fetch(logQuery).iterator(); assertEquals(request1Id, iterator.next().getRequestId()); assertEquals(request2Id, iterator.next().getRequestId()); assertFalse(iterator.hasNext()); logQuery = new LogQuery().requestIds(Arrays.asList(request2Id)); iterator = service.fetch(logQuery).iterator(); assertEquals(request2Id, iterator.next().getRequestId()); assertFalse(iterator.hasNext()); }
Example #5
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test @InSequence(20) public void testRequestLogsAreSortedNewestFirst() throws EntityNotFoundException { LogQuery query = new LogQuery().startTimeMillis(System.currentTimeMillis() - 60000); Iterator<RequestLogs> iterator = findLogLine(query, 3); Long previousEndTimeUsec = null; while (iterator.hasNext()) { RequestLogs requestLogs = iterator.next(); long endTimeUsec = requestLogs.getEndTimeUsec(); if (previousEndTimeUsec != null) { assertTrue( "RequestLogs with endTimeUsec " + endTimeUsec + " was returned after RequestLogs with endTimeUsec " + previousEndTimeUsec, previousEndTimeUsec >= endTimeUsec); } previousEndTimeUsec = endTimeUsec; } }
Example #6
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test @InSequence(20) public void testStartAndEndTimeUsec() throws Exception { RequestLogs requestLogs1 = getRequestLogs1(); long time1 = getTime(1); long time2 = getTime(2); long startTimeUsec = requestLogs1.getStartTimeUsec(); assertTrue("expected startTimeUsec to be >= " + time1 + ", but was " + startTimeUsec, startTimeUsec >= time1); assertTrue("expected startTimeUsec to be <= " + time2 + ", but was " + startTimeUsec, startTimeUsec <= time2); long endTimeUsec = requestLogs1.getEndTimeUsec(); assertTrue("expected endTimeUsec to be >= " + time1 + ", but was " + endTimeUsec, endTimeUsec >= time1); assertTrue("expected endTimeUsec to be <= " + time2 + ", but was " + endTimeUsec, endTimeUsec <= time2); assertTrue("expected endTimeUsec to be more than startTimeUsec, but it wasn't (startTime was " + startTimeUsec + "; endTime was " + endTimeUsec, startTimeUsec < endTimeUsec); }
Example #7
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 6 votes |
/** * These could return different values from the implementations so just assert the basics. */ @Test @InSequence(20) public void testMiscProperties() throws Exception { RequestLogs logs = getRequestLogs1(); assertNotNull("App Engine Release, e.g. 1.8.0, or empty string.", logs.getAppEngineRelease()); assertTrue("Estimated cost of this request, in dollars.", logs.getCost() >= 0.0); assertTrue("Time required to process this request in microseconds.", logs.getLatencyUsec() >= 0); assertTrue("Microseconds request spent in pending request queue, if was pending at all.", logs.getPendingTimeUsec() >= 0); assertFalse("This should never be a loading request: " + logs.toString(), logs.isLoadingRequest()); String appId = SystemProperty.applicationId.get(); // appIds have a prefix according to datacenter. assertTrue("The application ID that handled this request.", logs.getAppId().endsWith(appId)); long cycles = logs.getMcycles(); assertTrue("Number of machine cycles used to process this request: " + cycles, cycles >= 0); String getOffsetMsg = "Base64-encoded offset used with subsequent LogQuery to continue reading logs at the point in time immediately following this request."; assertNotNull(getOffsetMsg, logs.getOffset()); assertTrue("Should be Base64: " + logs.getOffset(), Base64.isBase64(logs.getOffset().getBytes())); String mapEntryMsg = "File or class within the URL mapping used for this request: " + logs.getUrlMapEntry(); assertNotNull(mapEntryMsg, logs.getUrlMapEntry()); }
Example #8
Source File: RequestStatusCheckerImpl.java From nomulus with Apache License 2.0 | 6 votes |
/** * Returns true if the given request is currently running. * * @see <a href="https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/log/LogQuery">appengine documentation</a> */ @Override public boolean isRunning(String requestLogId) { RequestLogs requestLogs = Iterables.getOnlyElement( logService.fetch( LogQuery.Builder .withRequestIds(Collections.singletonList(requestLogId)) .includeAppLogs(false) .includeIncomplete(true)), null); // requestLogs will be null if that requestLogId isn't found at all, which can happen if the // request is too new (it can take several seconds until the logs are available for "fetch"). // So we have to assume it's "running" in that case. if (requestLogs == null) { logger.atInfo().log( "Queried an unrecognized requestLogId %s - assume it's running", requestLogId); return true; } logger.atInfo().log( "Found logs for requestLogId %s - isFinished: %b", requestLogId, requestLogs.isFinished()); return !requestLogs.isFinished(); }
Example #9
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test @InSequence(20) public void testRequestIdCurrentRequest() throws Exception { RequestLogs logs = getCurrentRequestLogs(); assertNotNull(logs); String currentId = logs.getRequestId(); assertEquals(getCurrentRequestId(), currentId); }
Example #10
Source File: LogServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
private void assertLogQueryExecutes(LogQuery logQuery, String testName, List<String> exceptionList) { try { Iterable<RequestLogs> iterable = service.fetch(logQuery); iterable.iterator().hasNext(); } catch (Exception e) { exceptionList.add(testName + ": " + e.toString()); } }
Example #11
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
private RequestLogs getRequestLogs(String request1Id) { LogQuery logQuery = new LogQuery().requestIds(Collections.singletonList(request1Id)); Iterator<RequestLogs> iterator = findLogLine(logQuery, 2); if (iterator == null || !iterator.hasNext()) { return null; } return iterator.next(); }
Example #12
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test @InSequence(20) public void testIsFinishedCurrentRequest() throws Exception { RequestLogs logs = getCurrentRequestLogs(); assertNotNull(logs); assertFalse(logs.isFinished()); }
Example #13
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test @InSequence(20) public void testModuleId() throws Exception { RequestLogs requestLogs1 = getRequestLogs1(); String moduleId = requestLogs1.getModuleId(); assertEquals("default", moduleId); }
Example #14
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test @InSequence(20) public void testApplicationInfo() throws Exception { RequestLogs requestLogs1 = getRequestLogs1(); String versionId = requestLogs1.getVersionId(); assertTrue("1".equals(versionId) || versionId.startsWith("1.")); }
Example #15
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test @InSequence(20) public void testClientIp() throws Exception { RequestLogs requestLogs1 = getRequestLogs1(); Property ip = property("testClientIp"); if (ip.exists()) { assertEquals(ip.getPropertyValue(), requestLogs1.getIp()); } else { assertRegexpMatches(REGEX_IP4, requestLogs1.getIp()); } }
Example #16
Source File: LoggingTestBase.java From appengine-tck with Apache License 2.0 | 5 votes |
protected AppLogLine findLogLine(String text, LogQuery logQuery) { Iterable<RequestLogs> iterable = LogServiceFactory.getLogService().fetch(logQuery); for (RequestLogs logs : iterable) { for (AppLogLine logLine : logs.getAppLogLines()) { if (logLine.getLogMessage().contains(text)) { return logLine; } } } return null; }
Example #17
Source File: LoggingTestBase.java From appengine-tck with Apache License 2.0 | 5 votes |
protected Iterator<RequestLogs> findLogLine(LogQuery query, int retryMax) { LogService service = LogServiceFactory.getLogService(); Iterator<RequestLogs> iterator = null; for (int i = 0; i <= retryMax; i++) { iterator = service.fetch(query).iterator(); if (iterator.hasNext()) { return iterator; } pause(1500); } return iterator; }
Example #18
Source File: LogViewerServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); PrintWriter writer = resp.getWriter(); boolean applogs = true; if ("false".equals(req.getParameter("applogs"))) { applogs = false; } boolean combined = false; if ("true".equals(req.getParameter("combined"))) { combined = true; } LogQuery query = LogQuery.Builder.withIncludeAppLogs(true).includeIncomplete(true); for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(record.getStartTimeUsec() / 1000); writer.println(String.format("\nDate: %s", cal.getTime().toString())); if (combined) { writer.println("COMBINED:" + record.getCombined()); } else { writer.println("URL: " + record.getResource()); writer.println(""); } if (applogs) { List<AppLogLine> appLogs = record.getAppLogLines(); for (AppLogLine appLog : appLogs) { writer.println("[" + appLog.getLogLevel() + "] " + appLog.getLogMessage()); } } } }
Example #19
Source File: CompileLogsAction.java From teammates with GNU General Public License v2.0 | 5 votes |
private List<AppLogLine> getErrorLogs() { LogService logService = LogServiceFactory.getLogService(); long endTime = Instant.now().toEpochMilli(); // Sets the range to 6 minutes to slightly overlap the 5 minute email timer long queryRange = 1000 * 60 * 6; long startTime = endTime - queryRange; LogQuery q = LogQuery.Builder.withDefaults() .includeAppLogs(true) .startTimeMillis(startTime) .endTimeMillis(endTime) .minLogLevel(LogLevel.ERROR); Iterable<RequestLogs> logs = logService.fetch(q); List<AppLogLine> errorLogs = new ArrayList<>(); for (RequestLogs requestLogs : logs) { List<AppLogLine> logList = requestLogs.getAppLogLines(); for (AppLogLine currentLog : logList) { LogLevel logLevel = currentLog.getLogLevel(); if (LogLevel.FATAL == logLevel || LogLevel.ERROR == logLevel) { errorLogs.add(currentLog); } } } return errorLogs; }
Example #20
Source File: RequestStatusCheckerImplTest.java From nomulus with Apache License 2.0 | 5 votes |
@Test public void testIsRunning_finished() { RequestLogs requestLogs = new RequestLogs(); requestLogs.setFinished(true); when(RequestStatusCheckerImpl.logService.fetch(expectedLogQuery("12345678"))) .thenReturn(ImmutableList.of(requestLogs)); assertThat(requestStatusChecker.isRunning("12345678")).isFalse(); assertAboutLogs() .that(logHandler) .hasLogAtLevelWithMessage(Level.INFO, "isFinished: true"); }
Example #21
Source File: RequestStatusCheckerImplTest.java From nomulus with Apache License 2.0 | 5 votes |
@Test public void testIsRunning_notFinished() { RequestLogs requestLogs = new RequestLogs(); requestLogs.setFinished(false); when(RequestStatusCheckerImpl.logService.fetch(expectedLogQuery("12345678"))) .thenReturn(ImmutableList.of(requestLogs)); assertThat(requestStatusChecker.isRunning("12345678")).isTrue(); assertAboutLogs() .that(logHandler) .hasLogAtLevelWithMessage(Level.INFO, "isFinished: false"); }
Example #22
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test @InSequence(20) public void testHost() throws Exception { RequestLogs requestLogs1 = getRequestLogs1(); assertEquals(getServerHostAndPort(), requestLogs1.getHost()); }
Example #23
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private RequestLogs getCurrentRequestLogs() { return getRequestLogs(getCurrentRequestId()); }
Example #24
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private RequestLogs getRequestLogs2() throws EntityNotFoundException { return getRequestLogs(getRequest2Id()); }
Example #25
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private RequestLogs getRequestLogs3() throws EntityNotFoundException { return getRequestLogs(getRequest3Id()); }
Example #26
Source File: RequestLogsTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private RequestLogs getRequestLogs1() throws EntityNotFoundException { return getRequestLogs(getRequest1Id()); }
Example #27
Source File: LogQueryTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private void executeQuery(LogQuery logQuery) { LogService service = LogServiceFactory.getLogService(); Iterator<RequestLogs> iterator = service.fetch(logQuery).iterator(); }