Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / log / RequestLogs.java
blob936c780732867a7baa7b9345b696c493aade2ff4
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.log;
5 import com.google.appengine.api.log.LogService.LogLevel;
6 import com.google.apphosting.api.logservice.LogServicePb.LogLine;
7 import com.google.apphosting.api.logservice.LogServicePb.RequestLog;
9 import java.util.ArrayList;
10 import java.util.List;
12 /**
13 * RequestLogs contain all the log information for a single request. This
14 * includes the request log as well as any application logs (which may
15 * correspond to logging statements in the user's code or messages we have
16 * inserted to alert them to certain conditions we have noticed).
17 * Additionally, we include information about this request outside of those
18 * logs, such as how long the request took, the IP of the user performing the
19 * request, and so on.
23 public final class RequestLogs {
24 private String appId;
25 private String versionId;
26 private String requestId;
27 private String offset;
28 private String ip;
29 private String nickname;
30 private long startTimeUsec;
31 private long endTimeUsec;
32 private long latency;
33 private long mcycles;
34 private String method;
35 private String resource;
36 private String httpVersion;
37 private int status;
38 private long responseSize;
39 private String referrer;
40 private String userAgent;
41 private String urlMapEntry;
42 private String combined;
43 private long apiMcycles;
44 private String host;
45 private double cost;
46 private String taskQueueName;
47 private String taskName;
48 private boolean wasLoadingRequest;
49 private long pendingTime;
50 private int replicaIndex;
51 private boolean finished;
52 private String instanceKey;
53 private List<AppLogLine> appLogLines = new ArrayList<AppLogLine>();
55 /**
56 * Default, zero-argument constructor for RequestLogs.
58 public RequestLogs() {
62 /**
63 * Constructs a new (external-facing) RequestLogs from an (internal-facing)
64 * RequestLog. We scrub out any fields that the Protocol Buffer specification
65 * for {@link RequestLog} names as Google-only fields.
67 * @param requestLog The RequestLog returned by a Log Read RPC call.
68 * @param offset A String containing an encoded offset from the RequestLog.
70 protected RequestLogs(RequestLog requestLog, String offset) {
71 setAppId(requestLog.getAppId());
72 setVersionId(requestLog.getVersionId());
73 setRequestId(requestLog.getRequestId());
74 setOffset(offset);
75 setIp(requestLog.getIp());
76 setNickname(requestLog.getNickname());
77 setStartTimeUsec(requestLog.getStartTime());
78 setEndTimeUsec(requestLog.getEndTime());
79 setLatency(requestLog.getLatency());
80 setMcycles(requestLog.getMcycles());
81 setMethod(requestLog.getMethod());
82 setResource(requestLog.getResource());
83 setHttpVersion(requestLog.getHttpVersion());
84 setStatus(requestLog.getStatus());
85 setResponseSize(requestLog.getResponseSize());
86 setReferrer(requestLog.getReferrer());
87 setUserAgent(requestLog.getUserAgent());
88 setUrlMapEntry(requestLog.getUrlMapEntry());
89 setCombined(requestLog.getCombined());
90 setApiMcycles(requestLog.getApiMcycles());
91 setHost(requestLog.getHost());
92 setCost(requestLog.getCost());
93 setTaskQueueName(requestLog.getTaskQueueName());
94 setTaskName(requestLog.getTaskName());
95 setWasLoadingRequest(requestLog.isWasLoadingRequest());
96 setPendingTime(requestLog.getPendingTime());
97 setReplicaIndex(requestLog.getReplicaIndex());
98 setFinished(requestLog.isFinished());
99 setInstanceKey(requestLog.getCloneKey());
101 List<AppLogLine> appLogLines = getAppLogLines();
102 for (LogLine logLine : requestLog.lines()) {
103 LogLevel level = LogLevel.values()[logLine.getLevel()];
105 appLogLines.add(new AppLogLine(logLine.getTime(), level,
106 logLine.getLogMessage()));
111 * @deprecated This value is no longer meaningful.
112 * @return The number of machine cycles spent in API calls while processing
113 * this request.
115 @Deprecated
116 public long getApiMcycles() {
117 return apiMcycles;
121 * @return The application ID that handled this request.
123 public String getAppId() {
124 return appId;
128 * @return A list of application logs associated with this request.
130 public List<AppLogLine> getAppLogLines() {
131 return appLogLines;
135 * @return The Apache-format combined log entry for this request. While the
136 * information in this field can be constructed from the rest of this
137 * message, we include this method for convenience.
139 public String getCombined() {
140 return combined;
144 * @return The estimated cost of this request, in dollars.
146 public double getCost() {
147 return cost;
151 * @return The time at which the request was known to end processing, in
152 * microseconds since the Unix epoch.
154 public long getEndTimeUsec() {
155 return endTimeUsec;
159 * @return The Internet host and port number of the resource being requested.
161 public String getHost() {
162 return host;
166 * @return The HTTP version of this request.
168 public String getHttpVersion() {
169 return httpVersion;
173 * @return Mostly-unique identifier for the instance that handled the
174 * request, or the empty string.
176 public String getInstanceKey() {
177 return instanceKey;
181 * @return The origin IP address of this request.
183 public String getIp() {
184 return ip;
188 * @return The time required to process this request in microseconds.
190 public long getLatencyUsec() {
191 return latency;
195 * @return The number of machine cycles used to process this request.
197 public long getMcycles() {
198 return mcycles;
202 * @return The request's method (e.g., GET, PUT, POST).
204 public String getMethod() {
205 return method;
209 * @return The nickname of the user that made the request. An empty string is
210 * returned if the user is not logged in.
212 public String getNickname() {
213 return nickname;
217 * @return A Base64-encoded offset that may be used with a subsequent
218 * LogQuery to continue reading logs at the point in time immediately
219 * following this request.
221 public String getOffset() {
222 return offset;
226 * @return The time, in microseconds, that this request spent in the pending
227 * request queue, if it was pending at all.
229 public long getPendingTimeUsec() {
230 return pendingTime;
234 * @return The referrer URL of this request.
236 public String getReferrer() {
237 return referrer;
241 * @return The backend replica that handled the request, or -1 if not
242 * serviced by a backend.
244 public int getReplicaIndex() {
245 return replicaIndex;
249 * @return A globally unique identifier for a request, based on the request's
250 * starting time.
252 public String getRequestId() {
253 return requestId;
257 * @return The resource path on the server requested by the client. Contains
258 * only the path component of the request URL.
260 public String getResource() {
261 return resource;
265 * @return The size (in bytes) sent back to the client by this request.
267 public long getResponseSize() {
268 return responseSize;
272 * @return The time at which this request was known to have begun processing,
273 * in microseconds since the Unix epoch.
275 public long getStartTimeUsec() {
276 return startTimeUsec;
280 * @return The HTTP response status of this request.
282 public int getStatus() {
283 return status;
287 * @return The request's task name, if this request was generated via the
288 * Task Queue API.
290 public String getTaskName() {
291 return taskName;
295 * @return The request's queue name, if this request was generated via the
296 * Task Queue API.
298 public String getTaskQueueName() {
299 return taskQueueName;
303 * @return The file or class within the URL mapping used for this request.
304 * Useful for tracking down the source code which was responsible for
305 * managing the request, especially for multiply mapped handlers.
307 public String getUrlMapEntry() {
308 return urlMapEntry;
312 * @return The user agent used to make this request.
314 public String getUserAgent() {
315 return userAgent;
319 * @return The version of the application that handled this request.
321 public String getVersionId() {
322 return versionId;
326 * @return Whether or not this request has been finished. If not, this request
327 * is still active.
329 public boolean isFinished() {
330 return finished;
334 * @return Whether or not this request was a loading request.
336 public boolean isLoadingRequest() {
337 return wasLoadingRequest;
340 public void setApiMcycles(long apiMcycles) {
341 this.apiMcycles = apiMcycles;
344 public void setAppId(String appId) {
345 this.appId = appId;
348 public void setAppLogLines(List<AppLogLine> appLogLines) {
349 this.appLogLines = appLogLines;
352 public void setCombined(String combined) {
353 this.combined = combined;
356 public void setCost(double cost) {
357 this.cost = cost;
360 public void setEndTimeUsec(long endTimeUsec) {
361 this.endTimeUsec = endTimeUsec;
364 public void setFinished(boolean finished) {
365 this.finished = finished;
368 public void setHost(String host) {
369 this.host = host;
372 public void setHttpVersion(String httpVersion) {
373 this.httpVersion = httpVersion;
376 public void setInstanceKey(String instanceKey) {
377 this.instanceKey = instanceKey;
380 public void setIp(String ip) {
381 this.ip = ip;
384 public void setLatency(long latency) {
385 this.latency = latency;
388 public void setMcycles(long mcycles) {
389 this.mcycles = mcycles;
392 public void setMethod(String method) {
393 this.method = method;
396 public void setNickname(String nickname) {
397 this.nickname = nickname;
400 public void setOffset(String offset) {
401 this.offset = offset;
404 public void setPendingTime(long pendingTime) {
405 this.pendingTime = pendingTime;
408 public void setReferrer(String referrer) {
409 this.referrer = referrer;
412 public void setReplicaIndex(int replicaIndex) {
413 this.replicaIndex = replicaIndex;
416 public void setRequestId(String requestId) {
417 this.requestId = requestId;
420 public void setResource(String resource) {
421 this.resource = resource;
424 public void setResponseSize(long responseSize) {
425 this.responseSize = responseSize;
428 public void setStartTimeUsec(long startTimeUsec) {
429 this.startTimeUsec = startTimeUsec;
432 public void setStatus(int status) {
433 this.status = status;
436 public void setTaskName(String taskName) {
437 this.taskName = taskName;
440 public void setTaskQueueName(String taskQueueName) {
441 this.taskQueueName = taskQueueName;
444 public void setUrlMapEntry(String urlMapEntry) {
445 this.urlMapEntry = urlMapEntry;
448 public void setUserAgent(String userAgent) {
449 this.userAgent = userAgent;
452 public void setVersionId(String versionId) {
453 this.versionId = versionId;
456 public void setWasLoadingRequest(boolean wasLoadingRequest) {
457 this.wasLoadingRequest = wasLoadingRequest;
460 @Override
461 public String toString() {
462 return "RequestLogs{" +
463 "appId='" + appId + '\'' +
464 ", versionId='" + versionId + '\'' +
465 ", requestId='" + requestId + '\'' +
466 ", ip='" + ip + '\'' +
467 ", nickname='" + nickname + '\'' +
468 ", startTimeUsec=" + startTimeUsec +
469 ", endTimeUsec=" + endTimeUsec +
470 ", latency=" + latency +
471 ", mcycles=" + mcycles +
472 ", method='" + method + '\'' +
473 ", resource='" + resource + '\'' +
474 ", httpVersion='" + httpVersion + '\'' +
475 ", status=" + status +
476 ", responseSize=" + responseSize +
477 ", referrer='" + referrer + '\'' +
478 ", userAgent='" + userAgent + '\'' +
479 ", urlMapEntry='" + urlMapEntry + '\'' +
480 ", combined='" + combined + '\'' +
481 ", apiMcycles=" + apiMcycles +
482 ", host='" + host + '\'' +
483 ", cost=" + cost +
484 ", taskQueueName='" + taskQueueName + '\'' +
485 ", taskName='" + taskName + '\'' +
486 ", wasLoadingRequest=" + wasLoadingRequest +
487 ", pendingTime=" + pendingTime +
488 ", replicaIndex=" + replicaIndex +
489 ", finished=" + finished +
490 ", instanceKey='" + instanceKey + '\'' +
491 ", appLogLines=" + appLogLines +
492 '}';