Search in sources :

Example 1 with AppLogLine

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

the class AdminEmailLogPageAction method filterLogsForEmailLogPage.

private List<EmailLogEntry> filterLogsForEmailLogPage(List<AppLogLine> appLogLines, AdminEmailLogPageData data) {
    List<EmailLogEntry> emailLogs = new LinkedList<>();
    for (AppLogLine appLog : appLogLines) {
        String logMsg = appLog.getLogMessage();
        boolean isNotEmailLog = !logMsg.contains("TEAMMATESEMAILLOG");
        if (isNotEmailLog) {
            continue;
        }
        EmailLogEntry emailLogEntry = new EmailLogEntry(appLog);
        if (data.shouldShowLog(emailLogEntry)) {
            emailLogs.add(emailLogEntry);
        }
    }
    return emailLogs;
}
Also used : EmailLogEntry(teammates.common.util.EmailLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList)

Example 2 with AppLogLine

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

the class AdminEmailLogPageAction method searchEmailLogsWithTimeIncrement.

/**
 * Searches enough email logs within MAX_SEARCH_PERIOD hours.
 */
private void searchEmailLogsWithTimeIncrement(AdminEmailLogPageData data) {
    List<EmailLogEntry> emailLogs = new LinkedList<>();
    List<String> versionToQuery = getVersionsForQuery(data.getVersions());
    AdminLogQuery query = new AdminLogQuery(versionToQuery, null, data.getToDate());
    int 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 (emailLogs.size() >= LOGS_PER_PAGE) {
            break;
        }
        List<AppLogLine> searchResult = logApi.fetchLogs(query);
        List<EmailLogEntry> filteredLogs = filterLogsForEmailLogPage(searchResult, data);
        emailLogs.addAll(filteredLogs);
        totalLogsSearched += searchResult.size();
        query.moveTimePeriodBackward(SEARCH_TIME_INCREMENT);
    }
    data.setLogs(emailLogs);
    long nextEndTimeToSearch = query.getEndTime();
    String status = "&nbsp;&nbsp;Total Logs gone through in last search: " + totalLogsSearched + "<br>" + "<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button>";
    data.setStatusForAjax(status);
    statusToUser.add(new StatusMessage(status, StatusMessageColor.INFO));
}
Also used : EmailLogEntry(teammates.common.util.EmailLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList) AdminLogQuery(teammates.common.util.AdminLogQuery) GaeLogApi(teammates.common.util.GaeLogApi) StatusMessage(teammates.common.util.StatusMessage)

Example 3 with AppLogLine

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

the class GaeLogApi method fetchLogs.

/**
 * Retrieves logs using the query.
 * @return logs fetched from server.
 */
public List<AppLogLine> fetchLogs(AdminLogQuery query) {
    List<AppLogLine> logs = new LinkedList<>();
    // fetch request log
    Iterable<RequestLogs> records = LogServiceFactory.getLogService().fetch(query.getQuery());
    for (RequestLogs record : records) {
        // fetch application log
        List<AppLogLine> appLogLines = record.getAppLogLines();
        logs.addAll(appLogLines);
    }
    return logs;
}
Also used : AppLogLine(com.google.appengine.api.log.AppLogLine) RequestLogs(com.google.appengine.api.log.RequestLogs) LinkedList(java.util.LinkedList)

Example 4 with AppLogLine

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

the class EmailGeneratorTest method testGenerateCompiledLogsEmail.

@Test
public void testGenerateCompiledLogsEmail() throws IOException {
    AppLogLine typicalLogLine = new AppLogLine();
    typicalLogLine.setLogLevel(LogLevel.ERROR);
    typicalLogLine.setLogMessage("Typical log message");
    AppLogLine logLineWithLineBreak = new AppLogLine();
    logLineWithLineBreak.setLogLevel(LogLevel.ERROR);
    logLineWithLineBreak.setLogMessage("Log line \n with line break <br> and also HTML br tag");
    EmailWrapper email = new EmailGenerator().generateCompiledLogsEmail(Arrays.asList(typicalLogLine, logLineWithLineBreak));
    String subject = String.format(EmailType.SEVERE_LOGS_COMPILATION.getSubject(), Config.getAppVersion());
    verifyEmail(email, Config.SUPPORT_EMAIL, subject, "/severeLogsCompilationEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AppLogLine(com.google.appengine.api.log.AppLogLine) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 5 with AppLogLine

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

the class ActivityLogEntryTest method logEntry_withMalformationAppLogLine_constructionFail.

@Test
public void logEntry_withMalformationAppLogLine_constructionFail() {
    ______TS("Fail: log message not in correct format");
    AppLogLine appLog = new AppLogLine();
    appLog.setLogMessage("TEAMMATESLOG||RANDOM");
    ActivityLogEntry entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertTrue(entry.generateLogMessage().contains(Const.ActivityLog.MESSAGE_ERROR_LOG_MESSAGE_FORMAT));
    String logMessageMalformation = "TEAMMATESLOG|||instructorHome|||Pageload|||true|||Instructor" + "|||UserName|||UserId|||UserEmail|||Message|||URL";
    appLog.setLogMessage(logMessageMalformation);
    entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertTrue(entry.generateLogMessage().contains(Const.ActivityLog.MESSAGE_ERROR_LOG_MESSAGE_FORMAT));
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

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