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
.io
.Serializable
;
10 import java
.util
.ArrayList
;
11 import java
.util
.List
;
12 import java
.util
.Objects
;
15 * RequestLogs contain all the log information for a single request. This
16 * includes the request log as well as any application logs (which may
17 * correspond to logging statements in the user's code or messages we have
18 * inserted to alert them to certain conditions we have noticed).
19 * Additionally, we include information about this request outside of those
20 * logs, such as how long the request took, the IP of the user performing the
25 public final class RequestLogs
implements Serializable
{
26 private static final long serialVersionUID
= 7380961939323935275L;
29 private String moduleId
;
30 private String versionId
;
31 private String requestId
;
32 private String offset
;
34 private String nickname
;
35 private long startTimeUsec
;
36 private long endTimeUsec
;
39 private String method
;
40 private String resource
;
41 private String httpVersion
;
43 private long responseSize
;
44 private String referrer
;
45 private String userAgent
;
46 private String urlMapEntry
;
47 private String combined
;
48 private long apiMcycles
;
51 private String taskQueueName
;
52 private String taskName
;
53 private boolean wasLoadingRequest
;
54 private long pendingTime
;
55 private int replicaIndex
;
56 private boolean finished
;
57 private String instanceKey
;
58 private List
<AppLogLine
> appLogLines
= new ArrayList
<AppLogLine
>();
59 private String appEngineRelease
;
62 * Default, zero-argument constructor for RequestLogs.
64 public RequestLogs() {}
67 * Constructs a new (external-facing) RequestLogs from an (internal-facing)
68 * RequestLog. We scrub out any fields that the Protocol Buffer specification
69 * for {@link RequestLog} names as Google-only fields.
71 * @param requestLog The RequestLog returned by a Log Read RPC call.
72 * @param offset A String containing an encoded offset from the RequestLog.
74 protected RequestLogs(RequestLog requestLog
, String offset
) {
75 setAppId(requestLog
.getAppId());
76 setModuleId(requestLog
.getModuleId());
77 setVersionId(requestLog
.getVersionId());
78 setRequestId(requestLog
.getRequestId());
80 setIp(requestLog
.getIp());
81 setNickname(requestLog
.getNickname());
82 setStartTimeUsec(requestLog
.getStartTime());
83 setEndTimeUsec(requestLog
.getEndTime());
84 setLatency(requestLog
.getLatency());
85 setMcycles(requestLog
.getMcycles());
86 setMethod(requestLog
.getMethod());
87 setResource(requestLog
.getResource());
88 setHttpVersion(requestLog
.getHttpVersion());
89 setStatus(requestLog
.getStatus());
90 setResponseSize(requestLog
.getResponseSize());
91 setReferrer(requestLog
.getReferrer());
92 setUserAgent(requestLog
.getUserAgent());
93 setUrlMapEntry(requestLog
.getUrlMapEntry());
94 setCombined(requestLog
.getCombined());
95 setApiMcycles(requestLog
.getApiMcycles());
96 setHost(requestLog
.getHost());
97 setTaskQueueName(requestLog
.getTaskQueueName());
98 setTaskName(requestLog
.getTaskName());
99 setWasLoadingRequest(requestLog
.isWasLoadingRequest());
100 setPendingTime(requestLog
.getPendingTime());
101 setReplicaIndex(requestLog
.getReplicaIndex());
102 setFinished(requestLog
.isFinished());
103 setInstanceKey(requestLog
.getCloneKey());
104 setAppEngineRelease(requestLog
.getAppEngineRelease());
106 List
<AppLogLine
> appLogLines
= getAppLogLines();
107 for (LogLine logLine
: requestLog
.lines()) {
108 LogLevel level
= LogLevel
.values()[logLine
.getLevel()];
110 appLogLines
.add(new AppLogLine(logLine
.getTime(), level
,
111 logLine
.getLogMessage()));
116 * @deprecated This value is no longer meaningful.
117 * @return The number of machine cycles spent in API calls while processing
121 public long getApiMcycles() {
126 * @return The application ID that handled this request.
128 public String
getAppId() {
133 * @return A list of application logs associated with this request.
135 public List
<AppLogLine
> getAppLogLines() {
140 * @return The Apache-format combined log entry for this request. While the
141 * information in this field can be constructed from the rest of this
142 * message, we include this method for convenience.
144 public String
getCombined() {
149 * @return The estimated cost of this request, in dollars.
151 public double getCost() {
156 * @return The time at which the request was known to end processing, in
157 * microseconds since the Unix epoch.
159 public long getEndTimeUsec() {
164 * @return The Internet host and port number of the resource being requested.
166 public String
getHost() {
171 * @return The HTTP version of this request.
173 public String
getHttpVersion() {
178 * @return Mostly-unique identifier for the instance that handled the
179 * request, or the empty string.
181 public String
getInstanceKey() {
186 * @return The origin IP address of this request.
187 * App Engine uses an origin IP address from the 0.0.0.0/8 range when the request
189 * Some examples of web hooks are task queues, cron jobs and warming requests.
191 public String
getIp() {
196 * @return The time required to process this request in microseconds.
198 public long getLatencyUsec() {
203 * @return The number of machine cycles used to process this request.
205 public long getMcycles() {
210 * @return The request's method (e.g., GET, PUT, POST).
212 public String
getMethod() {
217 * @return The nickname of the user that made the request. An empty string is
218 * returned if the user is not logged in.
220 public String
getNickname() {
225 * @return A Base64-encoded offset that may be used with a subsequent
226 * LogQuery to continue reading logs at the point in time immediately
227 * following this request.
229 public String
getOffset() {
234 * @return The time, in microseconds, that this request spent in the pending
235 * request queue, if it was pending at all.
237 public long getPendingTimeUsec() {
242 * @return The referrer URL of this request.
244 public String
getReferrer() {
249 * @return The backend replica that handled the request, or -1 if not
250 * serviced by a backend.
252 public int getReplicaIndex() {
257 * @return A globally unique identifier for a request, based on the request's
260 public String
getRequestId() {
265 * @return The resource path on the server requested by the client. Contains
266 * only the path component of the request URL.
268 public String
getResource() {
273 * @return The size (in bytes) sent back to the client by this request.
275 public long getResponseSize() {
280 * @return The time at which this request was known to have begun processing,
281 * in microseconds since the Unix epoch.
283 public long getStartTimeUsec() {
284 return startTimeUsec
;
288 * @return The HTTP response status of this request.
290 public int getStatus() {
295 * @return The request's task name, if this request was generated via the
298 public String
getTaskName() {
303 * @return The request's queue name, if this request was generated via the
306 public String
getTaskQueueName() {
307 return taskQueueName
;
311 * @return The file or class within the URL mapping used for this request.
312 * Useful for tracking down the source code which was responsible for
313 * managing the request, especially for multiply mapped handlers.
315 public String
getUrlMapEntry() {
320 * @return The user agent used to make this request.
322 public String
getUserAgent() {
327 * @return The module of the application that handled this request.
329 public String
getModuleId() {
334 * @return The version of the application that handled this request.
336 public String
getVersionId() {
341 * @return Whether or not this request has been finished. If not, this request
344 public boolean isFinished() {
349 * @return Whether or not this request was a loading request.
351 public boolean isLoadingRequest() {
352 return wasLoadingRequest
;
356 * @return App Engine Release, e.g. "1.7.5", or the empty string.
358 public String
getAppEngineRelease() {
359 return appEngineRelease
;
362 public void setApiMcycles(long apiMcycles
) {
363 this.apiMcycles
= apiMcycles
;
366 public void setAppId(String appId
) {
370 public void setAppLogLines(List
<AppLogLine
> appLogLines
) {
371 this.appLogLines
= appLogLines
;
374 public void setCombined(String combined
) {
375 this.combined
= combined
;
378 public void setCost(double cost
) {
382 public void setEndTimeUsec(long endTimeUsec
) {
383 this.endTimeUsec
= endTimeUsec
;
386 public void setFinished(boolean finished
) {
387 this.finished
= finished
;
390 public void setHost(String host
) {
394 public void setHttpVersion(String httpVersion
) {
395 this.httpVersion
= httpVersion
;
398 public void setInstanceKey(String instanceKey
) {
399 this.instanceKey
= instanceKey
;
402 public void setIp(String ip
) {
406 public void setLatency(long latency
) {
407 this.latency
= latency
;
410 public void setMcycles(long mcycles
) {
411 this.mcycles
= mcycles
;
414 public void setMethod(String method
) {
415 this.method
= method
;
418 public void setNickname(String nickname
) {
419 this.nickname
= nickname
;
422 public void setOffset(String offset
) {
423 this.offset
= offset
;
426 public void setPendingTime(long pendingTime
) {
427 this.pendingTime
= pendingTime
;
430 public void setReferrer(String referrer
) {
431 this.referrer
= referrer
;
434 public void setReplicaIndex(int replicaIndex
) {
435 this.replicaIndex
= replicaIndex
;
438 public void setRequestId(String requestId
) {
439 this.requestId
= requestId
;
442 public void setResource(String resource
) {
443 this.resource
= resource
;
446 public void setResponseSize(long responseSize
) {
447 this.responseSize
= responseSize
;
450 public void setStartTimeUsec(long startTimeUsec
) {
451 this.startTimeUsec
= startTimeUsec
;
454 public void setStatus(int status
) {
455 this.status
= status
;
458 public void setTaskName(String taskName
) {
459 this.taskName
= taskName
;
462 public void setTaskQueueName(String taskQueueName
) {
463 this.taskQueueName
= taskQueueName
;
466 public void setUrlMapEntry(String urlMapEntry
) {
467 this.urlMapEntry
= urlMapEntry
;
470 public void setUserAgent(String userAgent
) {
471 this.userAgent
= userAgent
;
474 public void setModuleId(String moduleId
) {
475 this.moduleId
= moduleId
;
478 public void setVersionId(String versionId
) {
479 this.versionId
= versionId
;
482 public void setWasLoadingRequest(boolean wasLoadingRequest
) {
483 this.wasLoadingRequest
= wasLoadingRequest
;
486 public void setAppEngineRelease(String appEngineRelease
) {
487 this.appEngineRelease
= appEngineRelease
;
491 public String
toString() {
492 return "RequestLogs{" +
493 "appId='" + appId
+ '\'' +
494 ", moduleId='" + moduleId
+ '\'' +
495 ", versionId='" + versionId
+ '\'' +
496 ", requestId='" + requestId
+ '\'' +
497 ", ip='" + ip
+ '\'' +
498 ", nickname='" + nickname
+ '\'' +
499 ", startTimeUsec=" + startTimeUsec
+
500 ", endTimeUsec=" + endTimeUsec
+
501 ", latency=" + latency
+
502 ", mcycles=" + mcycles
+
503 ", method='" + method
+ '\'' +
504 ", resource='" + resource
+ '\'' +
505 ", httpVersion='" + httpVersion
+ '\'' +
506 ", status=" + status
+
507 ", responseSize=" + responseSize
+
508 ", referrer='" + referrer
+ '\'' +
509 ", userAgent='" + userAgent
+ '\'' +
510 ", urlMapEntry='" + urlMapEntry
+ '\'' +
511 ", combined='" + combined
+ '\'' +
512 ", apiMcycles=" + apiMcycles
+
513 ", host='" + host
+ '\'' +
515 ", taskQueueName='" + taskQueueName
+ '\'' +
516 ", taskName='" + taskName
+ '\'' +
517 ", wasLoadingRequest=" + wasLoadingRequest
+
518 ", pendingTime=" + pendingTime
+
519 ", replicaIndex=" + replicaIndex
+
520 ", finished=" + finished
+
521 ", instanceKey='" + instanceKey
+ '\'' +
522 ", appLogLines=" + appLogLines
+
523 ", appEngineRelease='" + appEngineRelease
+ '\'' +
528 public int hashCode() {
529 return Objects
.hash(appId
, moduleId
, versionId
, requestId
, offset
, ip
,
530 nickname
, startTimeUsec
, endTimeUsec
, latency
, mcycles
, method
,
531 resource
, httpVersion
, status
, responseSize
, referrer
, userAgent
,
532 urlMapEntry
, combined
, apiMcycles
, host
, cost
, taskQueueName
, taskName
,
533 wasLoadingRequest
, pendingTime
, replicaIndex
, finished
, instanceKey
,
534 appLogLines
, appEngineRelease
);
538 public boolean equals(Object obj
) {
543 if (obj
== null || getClass() != obj
.getClass()) {
547 RequestLogs other
= (RequestLogs
) obj
;
548 return Objects
.equals(appId
, other
.appId
)
549 && Objects
.equals(moduleId
, other
.moduleId
)
550 && Objects
.equals(versionId
, other
.versionId
)
551 && Objects
.equals(requestId
, other
.requestId
)
552 && Objects
.equals(offset
, other
.offset
)
553 && Objects
.equals(ip
, other
.ip
)
554 && Objects
.equals(nickname
, other
.nickname
)
555 && (startTimeUsec
== other
.startTimeUsec
)
556 && (endTimeUsec
== other
.endTimeUsec
)
557 && (latency
== other
.latency
)
558 && (mcycles
== other
.mcycles
)
559 && Objects
.equals(method
, other
.method
)
560 && Objects
.equals(resource
, other
.resource
)
561 && Objects
.equals(httpVersion
, other
.httpVersion
)
562 && (status
== other
.status
)
563 && (responseSize
== other
.responseSize
)
564 && Objects
.equals(referrer
, other
.referrer
)
565 && Objects
.equals(userAgent
, other
.userAgent
)
566 && Objects
.equals(urlMapEntry
, other
.urlMapEntry
)
567 && Objects
.equals(combined
, other
.combined
)
568 && (apiMcycles
== other
.apiMcycles
)
569 && Objects
.equals(host
, other
.host
)
570 && Objects
.equals(cost
, other
.cost
)
571 && Objects
.equals(taskQueueName
, other
.taskQueueName
)
572 && Objects
.equals(taskName
, other
.taskName
)
573 && (wasLoadingRequest
== other
.wasLoadingRequest
)
574 && (pendingTime
== other
.pendingTime
)
575 && (replicaIndex
== other
.replicaIndex
)
576 && (finished
== other
.finished
)
577 && Objects
.equals(instanceKey
, other
.instanceKey
)
578 && Objects
.equals(appLogLines
, other
.appLogLines
)
579 && Objects
.equals(appEngineRelease
, other
.appEngineRelease
);