use of com.google.apphosting.api.logservice.LogServicePb.LogLine in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testIncludeAppLogs.
@Test
public void testIncludeAppLogs() throws Exception {
boolean appLogsDesired = true;
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, appLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
// Try a test where we want app logs
List<Integer> expectedLogLevels = new ArrayList<>();
for (RequestLog item : Lists.reverse(allLogs)) {
for (LogLine line : item.getLineList()) {
expectedLogLevels.add(line.getLevel());
}
}
LogQuery query = LogQuery.Builder.withIncludeAppLogs(appLogsDesired);
List<Integer> actualLogLevels = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
for (AppLogLine line : record.getAppLogLines()) {
actualLogLevels.add(line.getLogLevel().ordinal());
}
}
String expectedLevels = joinAppLogLevels(expectedLogLevels);
String actualLevels = joinAppLogLevels(actualLogLevels);
assertThat(actualLevels).isEqualTo(expectedLevels);
// Now try a test where we don't want app logs
query.includeAppLogs(false);
List<Integer> actualLogLevelsForExcludedQuery = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
for (AppLogLine line : record.getAppLogLines()) {
actualLogLevelsForExcludedQuery.add(line.getLogLevel().ordinal());
}
}
assertThat(actualLogLevelsForExcludedQuery.size()).isEqualTo(0);
}
Aggregations