Search in sources :

Example 11 with AppLogLine

use of com.google.appengine.api.log.AppLogLine in project java-docs-samples by GoogleCloudPlatform.

the class LogsServlet method doGet.

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/html");
    PrintWriter writer = resp.getWriter();
    writer.println("<!DOCTYPE html>");
    writer.println("<meta charset=\"utf-8\">");
    writer.println("<title>App Engine Logs Sample</title>");
    // We use this to break out of our iteration loop, limiting record
    // display to 5 request logs at a time.
    int limit = 5;
    // This retrieves the offset from the Next link upon user click.
    String offset = req.getParameter("offset");
    // We want the App logs for each request log
    LogQuery query = LogQuery.Builder.withDefaults();
    query.includeAppLogs(true);
    // Set the offset value retrieved from the Next link click.
    if (offset != null) {
        query.offset(offset);
    }
    // This gets filled from the last request log in the iteration
    String lastOffset = null;
    int count = 0;
    // Display a few properties of each request log.
    for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) {
        writer.println("<br>REQUEST LOG <br>");
        DateTime reqTime = new DateTime(record.getStartTimeUsec() / 1000);
        writer.println("IP: " + record.getIp() + "<br>");
        writer.println("Method: " + record.getMethod() + "<br>");
        writer.println("Resource " + record.getResource() + "<br>");
        writer.println(String.format("<br>Date: %s", reqTime.toString()));
        lastOffset = record.getOffset();
        // Display all the app logs for each request log.
        for (AppLogLine appLog : record.getAppLogLines()) {
            writer.println("<br>" + "APPLICATION LOG" + "<br>");
            DateTime appTime = new DateTime(appLog.getTimeUsec() / 1000);
            writer.println(String.format("<br>Date: %s", appTime.toString()));
            writer.println("<br>Level: " + appLog.getLogLevel() + "<br>");
            writer.println("Message: " + appLog.getLogMessage() + "<br> <br>");
        }
        if (++count >= limit) {
            break;
        }
    }
    // When the user clicks this link, the offset is processed in the
    // GET handler and used to cycle through to the next 5 request logs.
    writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>", lastOffset));
}
Also used : LogQuery(com.google.appengine.api.log.LogQuery) AppLogLine(com.google.appengine.api.log.AppLogLine) RequestLogs(com.google.appengine.api.log.RequestLogs) DateTime(org.joda.time.DateTime) PrintWriter(java.io.PrintWriter)

Example 12 with AppLogLine

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

the class ActivityLogEntryTest method logEntry_withAppLogLine_constructSuccessfully.

@Test
public void logEntry_withAppLogLine_constructSuccessfully() {
    ______TS("Success: Generate activityLog from appLogLine (with TimeTaken)");
    String logMessageWithoutTimeTaken = "TEAMMATESLOG|||instructorHome|||Pageload|||true|||Instructor" + "|||UserName|||UserId|||UserEmail|||Message|||URL|||UserId20151019143729608";
    AppLogLine appLog = new AppLogLine();
    appLog.setLogMessage(logMessageWithoutTimeTaken + Const.ActivityLog.FIELD_SEPARATOR + "20");
    ActivityLogEntry entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(20, entry.getActionTimeTaken());
    ______TS("Success: Generate activityLog from appLogLine (without TimeTaken)");
    appLog.setLogMessage(logMessageWithoutTimeTaken);
    entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(0, entry.getActionTimeTaken());
    ______TS("Success with severe log: timeTaken not in correct format");
    appLog.setLogMessage(logMessageWithoutTimeTaken + Const.ActivityLog.FIELD_SEPARATOR + "random");
    entry = ActivityLogEntry.buildFromAppLog(appLog);
    assertEquals(logMessageWithoutTimeTaken, entry.generateLogMessage());
    assertEquals(0, entry.getActionTimeTaken());
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.testng.annotations.Test)

Example 13 with AppLogLine

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

the class AdminEmailLogPageAction method searchEmailLogsWithExactTimePeriod.

/**
 * Searches all logs in the time period specified in the query.
 */
private void searchEmailLogsWithExactTimePeriod(AdminEmailLogPageData data) {
    List<String> versionToQuery = getVersionsForQuery(data.getVersions());
    AdminLogQuery query = new AdminLogQuery(versionToQuery, data.getFromDate(), data.getToDate());
    List<AppLogLine> searchResult = new GaeLogApi().fetchLogs(query);
    data.setLogs(filterLogsForEmailLogPage(searchResult, data));
    long nextEndTimeToSearch = data.getFromDate() - 1;
    int totalLogsSearched = searchResult.size();
    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 : AppLogLine(com.google.appengine.api.log.AppLogLine) AdminLogQuery(teammates.common.util.AdminLogQuery) GaeLogApi(teammates.common.util.GaeLogApi) StatusMessage(teammates.common.util.StatusMessage)

Example 14 with AppLogLine

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

the class AdminActivityLogPageAction method filterLogsForActivityLogPage.

/**
 * Filters logs that should be shown on Admin Activity Log Page.
 */
private List<ActivityLogEntry> filterLogsForActivityLogPage(List<AppLogLine> appLogLines, AdminActivityLogPageData data) {
    List<ActivityLogEntry> appLogs = new LinkedList<>();
    for (AppLogLine appLog : appLogLines) {
        String logMsg = appLog.getLogMessage();
        boolean isNotTeammatesLog = !logMsg.contains("TEAMMATESLOG");
        boolean isLogFromAdminActivityLogPage = logMsg.contains("adminActivityLogPage");
        if (isNotTeammatesLog || isLogFromAdminActivityLogPage) {
            continue;
        }
        ActivityLogEntry activityLogEntry = ActivityLogEntry.buildFromAppLog(appLog);
        boolean isToShow = data.filterLog(activityLogEntry) && (!activityLogEntry.isTestingData() || data.getShouldShowTestData());
        if (!isToShow) {
            continue;
        }
        appLogs.add(activityLogEntry);
    }
    return appLogs;
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) AppLogLine(com.google.appengine.api.log.AppLogLine) LinkedList(java.util.LinkedList)

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