Search in sources :

Example 6 with LogLine

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);
}
Also used : BigInteger(java.math.BigInteger) RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) AppLogLine(com.google.appengine.api.log.AppLogLine) LogLine(com.google.apphosting.api.logservice.LogServicePb.LogLine) AppLogLine(com.google.appengine.api.log.AppLogLine) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Aggregations

LogLine (com.google.apphosting.api.logservice.LogServicePb.LogLine)6 RequestLog (com.google.apphosting.api.logservice.LogServicePb.RequestLog)6 AppLogLine (com.google.appengine.api.log.AppLogLine)4 ByteString (com.google.protobuf.ByteString)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 LogQuery (com.google.appengine.api.log.LogQuery)2 LogLevel (com.google.appengine.api.log.LogService.LogLevel)2 RequestLogs (com.google.appengine.api.log.RequestLogs)2 Test (org.junit.Test)2 LogModuleVersion (com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)1 LogOffset (com.google.apphosting.api.logservice.LogServicePb.LogOffset)1 LogReadResponse (com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)1 Level (java.util.logging.Level)1