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
;
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
23 public final class RequestLogs
{
25 private String versionId
;
26 private String requestId
;
27 private String offset
;
29 private String nickname
;
30 private long startTimeUsec
;
31 private long endTimeUsec
;
34 private String method
;
35 private String resource
;
36 private String httpVersion
;
38 private long responseSize
;
39 private String referrer
;
40 private String userAgent
;
41 private String urlMapEntry
;
42 private String combined
;
43 private long apiMcycles
;
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
>();
56 * Default, zero-argument constructor for RequestLogs.
58 public RequestLogs() {
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());
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
116 public long getApiMcycles() {
121 * @return The application ID that handled this request.
123 public String
getAppId() {
128 * @return A list of application logs associated with this request.
130 public List
<AppLogLine
> getAppLogLines() {
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() {
144 * @return The estimated cost of this request, in dollars.
146 public double getCost() {
151 * @return The time at which the request was known to end processing, in
152 * microseconds since the Unix epoch.
154 public long getEndTimeUsec() {
159 * @return The Internet host and port number of the resource being requested.
161 public String
getHost() {
166 * @return The HTTP version of this request.
168 public String
getHttpVersion() {
173 * @return Mostly-unique identifier for the instance that handled the
174 * request, or the empty string.
176 public String
getInstanceKey() {
181 * @return The origin IP address of this request.
183 public String
getIp() {
188 * @return The time required to process this request in microseconds.
190 public long getLatencyUsec() {
195 * @return The number of machine cycles used to process this request.
197 public long getMcycles() {
202 * @return The request's method (e.g., GET, PUT, POST).
204 public String
getMethod() {
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() {
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() {
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() {
234 * @return The referrer URL of this request.
236 public String
getReferrer() {
241 * @return The backend replica that handled the request, or -1 if not
242 * serviced by a backend.
244 public int getReplicaIndex() {
249 * @return A globally unique identifier for a request, based on the request's
252 public String
getRequestId() {
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() {
265 * @return The size (in bytes) sent back to the client by this request.
267 public long getResponseSize() {
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() {
287 * @return The request's task name, if this request was generated via the
290 public String
getTaskName() {
295 * @return The request's queue name, if this request was generated via the
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() {
312 * @return The user agent used to make this request.
314 public String
getUserAgent() {
319 * @return The version of the application that handled this request.
321 public String
getVersionId() {
326 * @return Whether or not this request has been finished. If not, this request
329 public boolean isFinished() {
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
) {
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
) {
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
) {
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
) {
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
;
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
+ '\'' +
484 ", taskQueueName='" + taskQueueName
+ '\'' +
485 ", taskName='" + taskName
+ '\'' +
486 ", wasLoadingRequest=" + wasLoadingRequest
+
487 ", pendingTime=" + pendingTime
+
488 ", replicaIndex=" + replicaIndex
+
489 ", finished=" + finished
+
490 ", instanceKey='" + instanceKey
+ '\'' +
491 ", appLogLines=" + appLogLines
+