本文整理汇总了Java中com.google.appengine.api.log.RequestLogs类的典型用法代码示例。如果您正苦于以下问题:Java RequestLogs类的具体用法?Java RequestLogs怎么用?Java RequestLogs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestLogs类属于com.google.appengine.api.log包,在下文中一共展示了RequestLogs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRunning
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
/**
* Returns true if the given request is currently running.
*
* @see <a href="https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/log/LogQuery">appengine documentation</a>
*/
@Override
public boolean isRunning(String requestLogId) {
RequestLogs requestLogs =
Iterables.getOnlyElement(
logService.fetch(
LogQuery.Builder
.withRequestIds(Collections.singletonList(requestLogId))
.includeAppLogs(false)
.includeIncomplete(true)),
null);
// requestLogs will be null if that requestLogId isn't found at all, which can happen if the
// request is too new (it can take several seconds until the logs are available for "fetch").
// So we have to assume it's "running" in that case.
if (requestLogs == null) {
logger.infofmt(
"Queried an unrecognized requestLogId %s - assume it's running", requestLogId);
return true;
}
logger.infofmt(
"Found logs for requestLogId %s - isFinished: %s", requestLogId, requestLogs.isFinished());
return !requestLogs.isFinished();
}
示例2: getMedianPendingTime
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@GET
@Path("/pending")
@Produces("text/plain")
public String getMedianPendingTime() {
LogService logService = LogServiceFactory.getLogService();
LogQuery logQuery = LogQuery.Builder.withIncludeAppLogs(false)
.startTimeMillis(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(60))
.endTimeMillis(System.currentTimeMillis());
StringBuilder content = new StringBuilder();
content.append("request.id,loading,pending,latency,mcycles\n");
Iterable<RequestLogs> logs = logService.fetch(logQuery);
for (RequestLogs log : logs) {
content.append(log.getRequestId()).append(",");
content.append(log.isLoadingRequest() ? "TRUE" : "FALSE").append(",");
content.append(log.getPendingTimeUsec()).append(",");
content.append(log.getLatencyUsec()).append(",");
content.append(log.getMcycles());
content.append("\n");
}
return content.toString();
}
示例3: doGet
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
if (req.getParameter("printLogs") != null) {
LogService ls = LogServiceFactory.getLogService();
LogQuery query = withIncludeAppLogs(true).minLogLevel(LogService.LogLevel.FATAL);
for (RequestLogs logs : ls.fetch(query)) {
for (AppLogLine logLine : logs.getAppLogLines()) {
if (logLine.getLogLevel().equals(LogService.LogLevel.FATAL)) {
resp.getWriter().println(logLine);
}
}
}
} else {
Logger logger = Logger.getLogger("com.foo");
resp.getWriter().println(logger.getLevel());
Logger logger2 = Logger.getLogger("com.foo.bar");
resp.getWriter().println(logger2.getLevel());
resp.getWriter().println(configRan);
logger2.severe("not null");
logger2.severe((String)null);
}
}
示例4: processLog
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Override
public void processLog(RequestLogs log) {
List<AppLogLine> logLines = log.getAppLogLines();
if ( logLines == null || logLines.size() <= 0 )
return;
List<AppLogLineEntity> appLogs = new ArrayList<AppLogLineEntity>();
LogLevel lvl = LogLevel.DEBUG;
for (AppLogLine logLine : logLines )
{
if ( LEVEL_PRIORITY.get(lvl) < LEVEL_PRIORITY.get(logLine.getLogLevel()) )
{
lvl = logLine.getLogLevel();
}
AppLogLineEntity ent = new AppLogLineEntity();
ent.setLogLevel(LEVEL_PRIORITY_NAME.get(lvl));
ent.setLogMessage(logLine.getLogMessage());
ent.setTimeUsec(logLine.getTimeUsec());
appLogs.add(ent);
}
level = LEVEL_PRIORITY_NAME.get(lvl);
logs = new Gson().toJson(appLogs);
}
示例5: testStartAndEndTimeUsec
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test
@InSequence(20)
public void testStartAndEndTimeUsec() throws Exception {
RequestLogs requestLogs1 = getRequestLogs1();
long time1 = getTime(1);
long time2 = getTime(2);
long startTimeUsec = requestLogs1.getStartTimeUsec();
assertTrue("expected startTimeUsec to be >= " + time1 + ", but was " + startTimeUsec, startTimeUsec >= time1);
assertTrue("expected startTimeUsec to be <= " + time2 + ", but was " + startTimeUsec, startTimeUsec <= time2);
long endTimeUsec = requestLogs1.getEndTimeUsec();
assertTrue("expected endTimeUsec to be >= " + time1 + ", but was " + endTimeUsec, endTimeUsec >= time1);
assertTrue("expected endTimeUsec to be <= " + time2 + ", but was " + endTimeUsec, endTimeUsec <= time2);
assertTrue("expected endTimeUsec to be more than startTimeUsec, but it wasn't (startTime was " + startTimeUsec + "; endTime was " + endTimeUsec, startTimeUsec < endTimeUsec);
}
示例6: testMiscProperties
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
/**
* These could return different values from the implementations so just assert the basics.
*/
@Test
@InSequence(20)
public void testMiscProperties() throws Exception {
RequestLogs logs = getRequestLogs1();
assertNotNull("App Engine Release, e.g. 1.8.0, or empty string.", logs.getAppEngineRelease());
assertTrue("Estimated cost of this request, in dollars.", logs.getCost() >= 0.0);
assertTrue("Time required to process this request in microseconds.", logs.getLatencyUsec() >= 0);
assertTrue("Microseconds request spent in pending request queue, if was pending at all.", logs.getPendingTimeUsec() >= 0);
assertFalse("This should never be a loading request: " + logs.toString(), logs.isLoadingRequest());
String appId = SystemProperty.applicationId.get(); // appIds have a prefix according to datacenter.
assertTrue("The application ID that handled this request.", logs.getAppId().endsWith(appId));
long cycles = logs.getMcycles();
assertTrue("Number of machine cycles used to process this request: " + cycles, cycles >= 0);
String getOffsetMsg = "Base64-encoded offset used with subsequent LogQuery to continue reading logs at the point in time immediately following this request.";
assertNotNull(getOffsetMsg, logs.getOffset());
assertTrue("Should be Base64: " + logs.getOffset(), Base64.isBase64(logs.getOffset().getBytes()));
String mapEntryMsg = "File or class within the URL mapping used for this request: " + logs.getUrlMapEntry();
assertNotNull(mapEntryMsg, logs.getUrlMapEntry());
}
示例7: testRequestLogsAreSortedNewestFirst
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test
@InSequence(20)
public void testRequestLogsAreSortedNewestFirst() throws EntityNotFoundException {
LogQuery query = new LogQuery().startTimeMillis(System.currentTimeMillis() - 60000);
Iterator<RequestLogs> iterator = findLogLine(query, 3);
Long previousEndTimeUsec = null;
while (iterator.hasNext()) {
RequestLogs requestLogs = iterator.next();
long endTimeUsec = requestLogs.getEndTimeUsec();
if (previousEndTimeUsec != null) {
assertTrue(
"RequestLogs with endTimeUsec " + endTimeUsec + " was returned after RequestLogs with endTimeUsec " + previousEndTimeUsec,
previousEndTimeUsec >= endTimeUsec);
}
previousEndTimeUsec = endTimeUsec;
}
}
示例8: testRequestIds
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test
@InSequence(20)
public void testRequestIds() throws Exception {
LogService service = LogServiceFactory.getLogService();
LogQuery logQuery = new LogQuery().requestIds(Arrays.asList(request1Id, request2Id));
Iterator<RequestLogs> iterator = service.fetch(logQuery).iterator();
assertEquals(request1Id, iterator.next().getRequestId());
assertEquals(request2Id, iterator.next().getRequestId());
assertFalse(iterator.hasNext());
logQuery = new LogQuery().requestIds(Arrays.asList(request2Id));
iterator = service.fetch(logQuery).iterator();
assertEquals(request2Id, iterator.next().getRequestId());
assertFalse(iterator.hasNext());
}
示例9: testLogLinesAreReturnedInSameOrderAsTheyAreLogged
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test
public void testLogLinesAreReturnedInSameOrderAsTheyAreLogged() {
String logMark = getTimeStampRandom();
String msg1 = "msg 1 " + logMark;
String msg2 = "msg 2 " + logMark;
log.log(Level.INFO, msg1);
log.log(Level.INFO, msg2);
flush(log);
sync(15000);
RequestLogs requestLogs = getCurrentRequestLogs();
Integer msg1Index = null;
Integer msg2Index = null;
int i = 0;
for (AppLogLine appLogLine : requestLogs.getAppLogLines()) {
if (appLogLine.getLogMessage().contains(msg1)) {
msg1Index = i;
} else if (appLogLine.getLogMessage().contains(msg2)) {
msg2Index = i;
}
i++;
}
assertNotNull("1st log message not found in appLogLines", msg1Index);
assertNotNull("2nd log message not found in appLogLines", msg2Index);
assertTrue("Expected first logged message to come before second logged message", msg1Index < msg2Index);
}
示例10: getCurrentRequestLogs
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
public RequestLogs getCurrentRequestLogs() {
LogQuery logQuery = new LogQuery()
.includeAppLogs(true)
.includeIncomplete(true)
.startTimeMillis(System.currentTimeMillis() - 20000);
for (RequestLogs requestLogs : LogServiceFactory.getLogService().fetch(logQuery)) {
if (requestLogs.getRequestId().equals(getCurrentRequestId())) {
return requestLogs;
}
}
fail("Could not find RequestLogs for current request");
return null;
// not sure, why the following code throws LogServiceException: An error occurred retrieving logs from storage.
// LogQuery logQuery = new LogQuery()
// .includeAppLogs(true)
// .requestIds(Collections.singletonList(getCurrentRequestId()));
// Iterable<RequestLogs> iterable = LogServiceFactory.getLogService().fetch(logQuery);
// assertTrue("Could not find RequestLogs for current request", iterable.iterator().hasNext());
// return iterable.iterator().next();
}
示例11: testIsRunning_notFinished
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test public void testIsRunning_notFinished() {
RequestLogs requestLogs = new RequestLogs();
requestLogs.setFinished(false);
when(RequestStatusCheckerImpl.logService.fetch(expectedLogQuery("12345678")))
.thenReturn(ImmutableList.of(requestLogs));
assertThat(requestStatusChecker.isRunning("12345678")).isTrue();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "isFinished: false");
}
示例12: testIsRunning_finished
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Test public void testIsRunning_finished() {
RequestLogs requestLogs = new RequestLogs();
requestLogs.setFinished(true);
when(RequestStatusCheckerImpl.logService.fetch(expectedLogQuery("12345678")))
.thenReturn(ImmutableList.of(requestLogs));
assertThat(requestStatusChecker.isRunning("12345678")).isFalse();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "isFinished: true");
}
示例13: getErrorLogs
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
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;
}
示例14: fetchLogs
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
/**
* 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;
}
示例15: doGet
import com.google.appengine.api.log.RequestLogs; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
PrintWriter writer = resp.getWriter();
boolean applogs = true;
if ("false".equals(req.getParameter("applogs"))) {
applogs = false;
}
boolean combined = false;
if ("true".equals(req.getParameter("combined"))) {
combined = true;
}
LogQuery query = LogQuery.Builder.withIncludeAppLogs(true).includeIncomplete(true);
for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(record.getStartTimeUsec() / 1000);
writer.println(String.format("\nDate: %s", cal.getTime().toString()));
if (combined) {
writer.println("COMBINED:" + record.getCombined());
} else {
writer.println("URL: " + record.getResource());
writer.println("");
}
if (applogs) {
List<AppLogLine> appLogs = record.getAppLogLines();
for (AppLogLine appLog : appLogs) {
writer.println("[" + appLog.getLogLevel() + "] " + appLog.getLogMessage());
}
}
}
}