Skip to content

Commit a864a97

Browse files
committed
Numerous style, license tweaks.
Replaced Calendar class with org.joda.time.DateTime.
1 parent b51621f commit a864a97

File tree

5 files changed

+61
-30
lines changed

5 files changed

+61
-30
lines changed

appengine/logs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Users Authentication sample for Google App Engine
22

3-
This sample demonstrates how to use the [Logs API][appid] on [Google App
3+
This sample demonstrates how to use the [Logs API][log-docs] on [Google App
44
Engine][ae-docs].
55

6-
[appid]: https://cloud.google.com/appengine/docs/java/logs/
6+
[log-docs]: https://cloud.google.com/appengine/docs/java/logs/
77
[ae-docs]: https://cloud.google.com/appengine/docs/java/
88

99
## Running locally
@@ -16,7 +16,7 @@ This example uses the
1616
[Maven gcloud plugin](https://cloud.google.com/appengine/docs/java/managed-vms/maven).
1717

1818
In the following command, replace YOUR-PROJECT-ID with your
19-
[Google Cloud Project ID](https://developers.google.com/console/help/new/#projectnumber) and SOME-VERSION with the desired version number.
19+
[Google Cloud Project ID](https://support.google.com/cloud/answer/6158840) and SOME-VERSION with the desired version number.
2020

2121
$ mvn appengine:update -Dappengine.appId=YOUR-PROJECT-ID -Dappengine.version=SOME-VERSION
2222

appengine/logs/pom.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright 2015 Google Inc. All Rights Reserved.
3+
Copyright 2016 Google Inc. All Rights Reserved.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@ Copyright 2015 Google Inc. All Rights Reserved.
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17+
<project>
1918
<modelVersion>4.0.0</modelVersion>
2019
<packaging>war</packaging>
2120
<version>1.0-SNAPSHOT</version>
@@ -51,7 +50,11 @@ Copyright 2015 Google Inc. All Rights Reserved.
5150
<artifactId>json</artifactId>
5251
<version>20151123</version>
5352
</dependency>
54-
53+
<dependency>
54+
<groupId>joda-time</groupId>
55+
<artifactId>joda-time</artifactId>
56+
<version>2.9.3</version>
57+
</dependency>
5558
</dependencies>
5659
<build>
5760
<!-- for hot reload of the web application -->

appengine/logs/src/main/java/com/example/appengine/logs/LogsServlet.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import com.google.appengine.api.log.LogServiceFactory;
2121
import com.google.appengine.api.log.RequestLogs;
2222

23+
import org.joda.time.DateTime;
24+
2325
import java.io.IOException;
2426
import java.io.PrintWriter;
25-
import java.util.Calendar;
2627

2728
import javax.servlet.http.HttpServlet;
2829
import javax.servlet.http.HttpServletRequest;
@@ -33,11 +34,15 @@
3334
// a time, using a Next link to cycle through to the next 5.
3435
public class LogsServlet extends HttpServlet {
3536
@Override
36-
public void doGet(HttpServletRequest req, HttpServletResponse resp)
37+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
3738
throws IOException {
3839

3940
resp.setContentType("text/html");
4041
PrintWriter writer = resp.getWriter();
42+
writer.println("<!DOCTYPE html>");
43+
writer.println("<meta charset=\"utf-8\">");
44+
writer.println("<title>App Engine Logs Sample</title>");
45+
4146
// We use this to break out of our iteration loop, limiting record
4247
// display to 5 request logs at a time.
4348
int limit = 5;
@@ -60,38 +65,33 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
6065

6166
// Display a few properties of each request log.
6267
for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) {
63-
writer.println("<br />REQUEST LOG <br />");
64-
Calendar cal = Calendar.getInstance();
65-
cal.setTimeInMillis(record.getStartTimeUsec() / 1000);
66-
67-
writer.println("IP: " + record.getIp() + "<br />");
68-
writer.println("Method: " + record.getMethod() + "<br />");
69-
writer.println("Resource " + record.getResource() + "<br />");
70-
writer.println(String.format("<br />Date: %s", cal.getTime().toString()));
68+
writer.println("<br>REQUEST LOG <br>");
69+
DateTime reqTime = new DateTime(record.getStartTimeUsec() / 1000);
70+
writer.println("IP: " + record.getIp() + "<br>");
71+
writer.println("Method: " + record.getMethod() + "<br>");
72+
writer.println("Resource " + record.getResource() + "<br>");
73+
writer.println(String.format("<br>Date: %s", reqTime.toString()));
7174

7275
lastOffset = record.getOffset();
7376

7477
// Display all the app logs for each request log.
7578
for (AppLogLine appLog : record.getAppLogLines()) {
76-
writer.println("<br />" + "APPLICATION LOG" + "<br />");
77-
Calendar appCal = Calendar.getInstance();
78-
appCal.setTimeInMillis(appLog.getTimeUsec() / 1000);
79-
writer.println(String.format("<br />Date: %s",
80-
appCal.getTime().toString()));
81-
writer.println("<br />Level: " + appLog.getLogLevel() + "<br />");
82-
writer.println("Message: " + appLog.getLogMessage() + "<br /> <br />");
83-
} //for each log line
79+
writer.println("<br>" + "APPLICATION LOG" + "<br>");
80+
DateTime appTime = new DateTime(appLog.getTimeUsec() / 1000);
81+
writer.println(String.format("<br>Date: %s", appTime.toString()));
82+
writer.println("<br>Level: " + appLog.getLogLevel() + "<br>");
83+
writer.println("Message: " + appLog.getLogMessage() + "<br> <br>");
84+
}
8485

8586
if (++count >= limit) {
8687
break;
8788
}
88-
} // for each record
89+
}
8990

9091
// When the user clicks this link, the offset is processed in the
9192
// GET handler and used to cycle through to the next 5 request logs.
92-
writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>",
93-
lastOffset));
94-
} // end doGet
95-
} //end class
93+
writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>", lastOffset));
94+
}
95+
}
9696
// [END logs_API_example]
9797

appengine/logs/src/main/webapp/WEB-INF/appengine-web.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE] -->
3+
<!--
4+
Copyright 2016 Google Inc. All Rights Reserved.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
-->
15+
<!-- [END_EXCLUDE] -->
216
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
317
<application>YOUR-PROJECT-ID</application>
418
<version>YOUR-VERSION-NUMBER</version>

appengine/logs/src/main/webapp/WEB-INF/web.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE] -->
3+
<!--
4+
Copyright 2016 Google Inc. All Rights Reserved.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
-->
15+
<!-- [END_EXCLUDE] -->
216
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
317
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
418
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

0 commit comments

Comments
 (0)