Search in sources :

Example 6 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project teammates by TEAMMATES.

the class EmailLogEntryTest method emailLog_withAppLogLine_constructionFailAsNotInCorrectFormat.

@Test
public void emailLog_withAppLogLine_constructionFailAsNotInCorrectFormat() {
    String logMessage = "NotInDesiredFormat";
    AppLogLine appLog = new AppLogLine();
    appLog.setLogMessage(logMessage);
    appLog.setTimeUsec(410333L);
    EmailLogEntry logEntry = new EmailLogEntry(appLog);
    assertEquals("", logEntry.getReceiver());
    assertEquals("", logEntry.getSubject());
    assertEquals("", logEntry.getContent());
    assertEquals(410L, logEntry.getTime());
    assertFalse(logEntry.isTestData());
}
Also used : EmailLogEntry(teammates.common.util.EmailLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

Example 7 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project teammates by TEAMMATES.

the class EmailLogEntryTest method emailLog_withAppLogLine_constructCorrectly.

@Test
public void emailLog_withAppLogLine_constructCorrectly() {
    String logMessage = "TEAMMATESEMAILLOG|||myRecipient@email.com|||mySubject|||myContent";
    AppLogLine appLog = new AppLogLine();
    appLog.setLogMessage(logMessage);
    appLog.setTimeUsec(2456L);
    EmailLogEntry logEntry = new EmailLogEntry(appLog);
    assertEquals(logMessage, logEntry.generateLogMessage());
    assertEquals("myRecipient@email.com", logEntry.getReceiver());
    assertEquals("mySubject", logEntry.getSubject());
    assertEquals("myContent", logEntry.getContent());
    assertEquals(2L, logEntry.getTime());
    assertFalse(logEntry.isTestData());
}
Also used : EmailLogEntry(teammates.common.util.EmailLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

Example 8 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method searchLogsWithExactTimePeriod.

/**
 * Retrieves all logs in the time period specified in the query.
 */
private List<ActivityLogEntry> searchLogsWithExactTimePeriod(AdminLogQuery query, AdminActivityLogPageData data) {
    GaeLogApi logApi = new GaeLogApi();
    List<AppLogLine> searchResult = logApi.fetchLogs(query);
    nextEndTimeToSearch = data.getFromDate() - 1;
    totalLogsSearched = searchResult.size();
    return filterLogsForActivityLogPage(searchResult, data);
}
Also used : AppLogLine(com.google.appengine.api.log.AppLogLine) GaeLogApi(teammates.common.util.GaeLogApi)

Example 9 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method searchLogsWithTimeIncrement.

/**
 * Retrieves enough logs within MAX_SEARCH_PERIOD hours.
 */
private List<ActivityLogEntry> searchLogsWithTimeIncrement(AdminLogQuery query, AdminActivityLogPageData data) {
    List<ActivityLogEntry> appLogs = new LinkedList<>();
    totalLogsSearched = 0;
    GaeLogApi logApi = new GaeLogApi();
    long startTime = query.getEndTime() - SEARCH_TIME_INCREMENT;
    query.setTimePeriod(startTime, query.getEndTime());
    for (int i = 0; i < MAX_SEARCH_TIMES; i++) {
        if (appLogs.size() >= RELEVANT_LOGS_PER_PAGE) {
            break;
        }
        List<AppLogLine> searchResult = logApi.fetchLogs(query);
        List<ActivityLogEntry> filteredLogs = filterLogsForActivityLogPage(searchResult, data);
        appLogs.addAll(filteredLogs);
        totalLogsSearched += searchResult.size();
        query.moveTimePeriodBackward(SEARCH_TIME_INCREMENT);
    }
    data.setFromDate(query.getStartTime() + SEARCH_TIME_INCREMENT);
    nextEndTimeToSearch = query.getEndTime();
    return appLogs;
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList) GaeLogApi(teammates.common.util.GaeLogApi)

Example 10 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project teammates by TEAMMATES.

the class CompileLogsAction method getErrorLogs.

private List<AppLogLine> getErrorLogs() {
    LogService logService = LogServiceFactory.getLogService();
    long endTime = new Date().getTime();
    // 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;
}
Also used : LogQuery(com.google.appengine.api.log.LogQuery) ArrayList(java.util.ArrayList) AppLogLine(com.google.appengine.api.log.AppLogLine) RequestLogs(com.google.appengine.api.log.RequestLogs) LogService(com.google.appengine.api.log.LogService) Date(java.util.Date) LogLevel(com.google.appengine.api.log.LogService.LogLevel)

Aggregations

AppLogLine (com.google.appengine.api.log.AppLogLine)14 LinkedList (java.util.LinkedList)5 Test (org.testng.annotations.Test)5 ActivityLogEntry (teammates.common.util.ActivityLogEntry)4 EmailLogEntry (teammates.common.util.EmailLogEntry)4 GaeLogApi (teammates.common.util.GaeLogApi)4 RequestLogs (com.google.appengine.api.log.RequestLogs)3 LogQuery (com.google.appengine.api.log.LogQuery)2 AdminLogQuery (teammates.common.util.AdminLogQuery)2 StatusMessage (teammates.common.util.StatusMessage)2 LogService (com.google.appengine.api.log.LogService)1 LogLevel (com.google.appengine.api.log.LogService.LogLevel)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 EmailWrapper (teammates.common.util.EmailWrapper)1 EmailGenerator (teammates.logic.api.EmailGenerator)1