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));
}
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());
}
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 = " 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));
}
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;
}
Aggregations