use of com.google.appengine.api.log.RequestLogs 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;
}
use of com.google.appengine.api.log.RequestLogs 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;
}
use of com.google.appengine.api.log.RequestLogs 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));
}
Aggregations