protected AppLogLine findLogLineContaining(String text, int retryMax) { LogQuery logQuery = new LogQuery() .includeAppLogs(true) .includeIncomplete(true) // Not specifying start time causes test to time out since it searches // all the logs. .startTimeMillis(System.currentTimeMillis() - (20 * 1000)); return findLogLine(text, logQuery, retryMax); }
public Iterable<RequestLogs> queryForLogs(long logRangeStartMs, long logRangeEndMs, LogsExportConfiguration exportConfig, LogsFieldExporterSet exporterSet) { LogService ls = LogServiceFactory.getLogService(); LogQuery lq = new LogQuery(); lq = lq.startTimeMillis(logRangeStartMs) .endTimeMillis(logRangeEndMs) .includeAppLogs(true); if (exportConfig.getLogLevel() != null) { lq = lq.minLogLevel(exportConfig.getLogLevel()); } List<Version> appVersions = exporterSet.applicationVersionsToExport(); if (appVersions != null && appVersions.size() > 0) { lq = lq.versions(appVersions); } Iterable<RequestLogs> logs = ls.fetch(lq); return logs; } }
@Test public void testLogLinesAreReturnedOnlyWhenRequested() { Logger log = Logger.getLogger(LogServiceTest.class.getName()); log.info("hello_testLogLinesAreReturnedOnlyWhenRequested"); flush(log); for (RequestLogs logs : service.fetch(new LogQuery().includeIncomplete(true).includeAppLogs(false))) { assertTrue("AppLogLines should be empty", logs.getAppLogLines().isEmpty()); } for (RequestLogs logs : service.fetch(new LogQuery().includeIncomplete(true).includeAppLogs(true))) { if (!logs.getAppLogLines().isEmpty()) { // if we've found at least one appLogLine, the test passed return; } } fail("Should have found at least one appLogLine, but didn't find any"); }
@Test @InSequence(20) public void testIncomplete() throws Exception { // GAE dev server doesn't handle this assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); String infoLogMsg = "info_incompleteRequest-" + System.currentTimeMillis(); log.info(infoLogMsg); flush(log); sync(5000); // Yes, even after a flush we need to wait for the logs to be available. assertLogQueryReturns(infoLogMsg, new LogQuery().includeAppLogs(true).includeIncomplete(true)); assertLogQueryReturns("info_createCompleteRequest1", new LogQuery().includeAppLogs(true).includeIncomplete(true)); assertLogQueryDoesNotReturn(infoLogMsg, new LogQuery().includeAppLogs(true) .includeIncomplete(false).startTimeMillis(System.currentTimeMillis() - 60000)); }
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(); } }
assertLogQueryExecutes(new LogQuery().includeIncomplete(true), "testIncludeIncompleteTrue", exceptions); assertLogQueryExecutes(new LogQuery().includeIncomplete(false), "testIncludeIncompleteFalse", exceptions); assertLogQueryExecutes(new LogQuery().includeAppLogs(true), "testIncludeAppLogsTrue", exceptions); assertLogQueryExecutes(new LogQuery().includeAppLogs(false), "testIncludeAppLogsFalse", exceptions); assertLogQueryExecutes(new LogQuery().batchSize(20), "testBatchSize", exceptions); assertLogQueryExecutes(new LogQuery().offset(null), "testOffset", exceptions); .minLogLevel(LogService.LogLevel.WARN) .includeIncomplete(true) .includeAppLogs(true) .batchSize(20) .offset(null)
.withMinLogLevel(LogService.LogLevel.WARN) .includeIncomplete(true) .includeAppLogs(true) .batchSize(20) .offset(null)
@Test @InSequence(20) public void testMinLogLevel() throws Exception { sync(5000); // Wait for previous requests. String infoLogMsg = "info_incompleteRequest-" + System.currentTimeMillis(); log.info(infoLogMsg); flush(log); sync(5000); // Yes, even after a flush we need to wait for the logs to be available. LogQuery debugLogQuery = new LogQuery().includeAppLogs(true).includeIncomplete(true).minLogLevel(DEBUG); assertLogQueryReturns("info_createCompleteRequest1", debugLogQuery); assertLogQueryReturns("warning_createCompleteRequest1", debugLogQuery); assertLogQueryReturns("severe_createCompleteRequest2", debugLogQuery); assertLogQueryReturns("info_createCompleteRequest3", debugLogQuery); assertLogQueryReturns(infoLogMsg, debugLogQuery); LogQuery warnLogQuery = new LogQuery().includeAppLogs(true).includeIncomplete(true).minLogLevel(WARN); assertLogQueryReturns("info_createCompleteRequest1", warnLogQuery); assertLogQueryReturns("warning_createCompleteRequest1", warnLogQuery); assertLogQueryReturns("severe_createCompleteRequest2", warnLogQuery); assertLogQueryDoesNotReturn("info_createCompleteRequest3", warnLogQuery); assertLogQueryDoesNotReturn(infoLogMsg, warnLogQuery); LogQuery errorLogQuery = new LogQuery().includeAppLogs(true).includeIncomplete(true).minLogLevel(ERROR); assertLogQueryReturns("severe_createCompleteRequest2", errorLogQuery); assertLogQueryDoesNotReturn("info_createCompleteRequest1", errorLogQuery); assertLogQueryDoesNotReturn("warning_createCompleteRequest1", errorLogQuery); assertLogQueryDoesNotReturn("info_createCompleteRequest3", errorLogQuery); assertLogQueryDoesNotReturn(infoLogMsg, errorLogQuery); }
.minLogLevel(LogService.LogLevel.WARN) .includeIncomplete(true) .includeAppLogs(true) .offset(null) .majorVersionIds(majorVersions);