Skip to content

Commit 774386a

Browse files
ludochgae-java-bot
authored andcommitted
Migrate App Engine dev components to GoogleLogger (Flogger).
PiperOrigin-RevId: 873072592 Change-Id: Ia8b11ce1faadbd475de8a70f28388672e1f54ca1
1 parent c8a3c84 commit 774386a

82 files changed

Lines changed: 1000 additions & 1106 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<url>https://github.com/GoogleCloudPlatform/appengine-java-standard/</url>
3232
<description>API for Google App Engine standard environment</description>
3333
<dependencies>
34+
<dependency>
35+
<groupId>com.google.flogger</groupId>
36+
<artifactId>google-extensions</artifactId>
37+
</dependency>
3438
<dependency>
3539
<groupId>com.google.appengine</groupId>
3640
<artifactId>protos</artifactId>

api_dev/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,10 @@
161161
<dependency>
162162
<groupId>com.google.flogger</groupId>
163163
<artifactId>flogger-system-backend</artifactId>
164-
<scope>test</scope>
165164
</dependency>
166165
<dependency>
167166
<groupId>com.google.flogger</groupId>
168167
<artifactId>google-extensions</artifactId>
169-
<scope>test</scope>
170168
</dependency>
171169
<dependency>
172170
<groupId>joda-time</groupId>

api_dev/src/main/java/com/google/appengine/api/appidentity/dev/LocalAppIdentityService.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.google.apphosting.api.ApiProxy;
3838
import com.google.auto.service.AutoService;
3939
import com.google.common.base.CharMatcher;
40+
import com.google.common.flogger.GoogleLogger;
4041
import com.google.common.io.BaseEncoding;
4142
import com.google.protobuf.ByteString;
4243
// <internal24>
@@ -49,8 +50,6 @@
4950
import java.security.spec.EncodedKeySpec;
5051
import java.security.spec.PKCS8EncodedKeySpec;
5152
import java.util.Map;
52-
import java.util.logging.Level;
53-
import java.util.logging.Logger;
5453

5554
/**
5655
* Stub implementation of the app identity service.
@@ -59,7 +58,7 @@
5958
@AutoService(LocalRpcService.class)
6059
public class LocalAppIdentityService extends AbstractLocalRpcService {
6160

62-
private static final Logger log = Logger.getLogger(LocalAppIdentityService.class.getName());
61+
private static final GoogleLogger log = GoogleLogger.forEnclosingClass();
6362
public static final String PACKAGE = "app_identity_service";
6463

6564
public static final String PRIVATE_KEY_PATH =
@@ -183,11 +182,9 @@ public GetAccessTokenResponse getAccessToken(Status status, GetAccessTokenReques
183182
}
184183
// Return an invalid token. There is no application default and dev_appserver does not have
185184
// access to an actual service account.
186-
log.log(
187-
Level.WARNING,
188-
"No Application Default credential, using an invalid token. "
189-
+ " If needed, you may want to call the gcloud command: "
190-
+ "`gcloud auth application-default login`");
185+
log.atWarning().log(
186+
"No Application Default credential, using an invalid token. If needed, you may want to"
187+
+ " call the gcloud command: `gcloud auth application-default login`");
191188

192189
StringBuilder builder = new StringBuilder();
193190
builder.append("InvalidToken");

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/LocalBlobstoreService.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.appengine.api.blobstore.BlobInfo;
2222
import com.google.appengine.api.blobstore.BlobKey;
2323
import com.google.appengine.api.blobstore.BlobstoreService;
24-
import com.google.appengine.api.blobstore.BlobstoreServicePb.BlobstoreServiceError;
24+
import com.google.appengine.api.blobstore.BlobstoreServicePb.BlobstoreServiceError.ErrorCode;
2525
import com.google.appengine.api.blobstore.BlobstoreServicePb.CreateEncodedGoogleStorageKeyRequest;
2626
import com.google.appengine.api.blobstore.BlobstoreServicePb.CreateEncodedGoogleStorageKeyResponse;
2727
import com.google.appengine.api.blobstore.BlobstoreServicePb.CreateUploadURLRequest;
@@ -36,6 +36,7 @@
3636
import com.google.apphosting.api.proto2api.ApiBasePb.VoidProto;
3737
import com.google.apphosting.utils.config.GenerationDirectory;
3838
import com.google.auto.service.AutoService;
39+
import com.google.common.flogger.GoogleLogger;
3940
import com.google.common.io.ByteStreams;
4041
import com.google.common.io.Closeables;
4142
import com.google.common.io.Files;
@@ -44,8 +45,6 @@
4445
import java.io.IOException;
4546
import java.io.InputStream;
4647
import java.util.Map;
47-
import java.util.logging.Level;
48-
import java.util.logging.Logger;
4948

5049
/**
5150
* Implementation of local blobstore service.
@@ -58,8 +57,7 @@ public final class LocalBlobstoreService extends AbstractLocalRpcService {
5857
// cannot access that definition due to packaging for unit tests.
5958
private static final String PORT_ID_ENV_ATTRIBUTE = "com.google.appengine.instance.port";
6059

61-
private static final Logger logger = Logger.getLogger(
62-
LocalBlobstoreService.class.getName());
60+
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
6361

6462
/**
6563
* Where to read/store the blobs from/to.
@@ -104,16 +102,17 @@ public void init(LocalServiceContext context, Map<String, String> properties) {
104102
String filePath = properties.get(BACKING_STORE_PROPERTY);
105103
File file;
106104
if (filePath != null) {
107-
logger.log(Level.INFO, "Creating blobstore backing store at " + filePath);
105+
logger.atInfo().log("Creating blobstore backing store at %s", filePath);
108106
file = new File(filePath);
109107
} else {
110108
file = GenerationDirectory.getGenerationDirectory(
111109
context.getLocalServerEnvironment().getAppDir());
112110
}
113111
file.mkdirs();
114112
if (!file.canWrite()) {
115-
logger.log(Level.WARNING, "Default blobstore file location is not writable, " +
116-
"creating a temporary directory. State will not be persisted between restarts.");
113+
logger.atWarning().log(
114+
"Default blobstore file location is not writable, "
115+
+ "creating a temporary directory. State will not be persisted between restarts.");
117116
file = Files.createTempDir();
118117
}
119118
BlobStorageFactory.setFileBlobStorage(file);
@@ -161,9 +160,8 @@ public VoidProto deleteBlob(Status status, final DeleteBlobRequest request) {
161160
try {
162161
blobStorage.deleteBlob(blobKey);
163162
} catch (IOException ex) {
164-
logger.log(Level.WARNING, "Could not delete blob: " + blobKey, ex);
165163
throw new ApiProxy.ApplicationException(
166-
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
164+
ErrorCode.INTERNAL_ERROR_VALUE, "Could not delete blob: " + blobKey + ": " + ex);
167165
}
168166
}
169167
}
@@ -174,21 +172,18 @@ public VoidProto deleteBlob(Status status, final DeleteBlobRequest request) {
174172
public FetchDataResponse fetchData(Status status, final FetchDataRequest request) {
175173
if (request.getStartIndex() < 0) {
176174
throw new ApiProxy.ApplicationException(
177-
BlobstoreServiceError.ErrorCode.DATA_INDEX_OUT_OF_RANGE_VALUE,
178-
"Start index must be >= 0.");
175+
ErrorCode.DATA_INDEX_OUT_OF_RANGE_VALUE, "Start index must be >= 0.");
179176
}
180177

181178
if (request.getEndIndex() < request.getStartIndex()) {
182179
throw new ApiProxy.ApplicationException(
183-
BlobstoreServiceError.ErrorCode.DATA_INDEX_OUT_OF_RANGE_VALUE,
184-
"End index must be >= startIndex.");
180+
ErrorCode.DATA_INDEX_OUT_OF_RANGE_VALUE, "End index must be >= startIndex.");
185181
}
186182

187183
long fetchSize = request.getEndIndex() - request.getStartIndex() + 1;
188184
if (fetchSize > BlobstoreService.MAX_BLOB_FETCH_SIZE) {
189185
throw new ApiProxy.ApplicationException(
190-
BlobstoreServiceError.ErrorCode.BLOB_FETCH_SIZE_TOO_LARGE_VALUE,
191-
"Blob fetch size too large.");
186+
ErrorCode.BLOB_FETCH_SIZE_TOO_LARGE_VALUE, "Blob fetch size too large.");
192187
}
193188

194189
final FetchDataResponse.Builder response = FetchDataResponse.newBuilder();
@@ -199,8 +194,7 @@ public FetchDataResponse fetchData(Status status, final FetchDataRequest request
199194
blobInfo = blobInfoStorage.loadGsFileInfo(blobKey);
200195
}
201196
if (blobInfo == null) {
202-
throw new ApiProxy.ApplicationException(
203-
BlobstoreServiceError.ErrorCode.BLOB_NOT_FOUND_VALUE, "Blob not found.");
197+
throw new ApiProxy.ApplicationException(ErrorCode.BLOB_NOT_FOUND_VALUE, "Blob not found.");
204198
}
205199

206200
final long endIndex;
@@ -226,9 +220,8 @@ public FetchDataResponse fetchData(Status status, final FetchDataRequest request
226220
Closeables.close(stream, swallowDueToThrow);
227221
}
228222
} catch (IOException ex) {
229-
logger.log(Level.WARNING, "Could not fetch data: " + blobKey, ex);
230223
throw new ApiProxy.ApplicationException(
231-
BlobstoreServiceError.ErrorCode.INTERNAL_ERROR_VALUE, ex.toString());
224+
ErrorCode.INTERNAL_ERROR_VALUE, "Could not fetch data: " + blobKey + ": " + ex);
232225
}
233226

234227
response.setData(ByteString.copyFrom(data));

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/ServeBlobFilter.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import com.google.appengine.api.blobstore.ByteRange;
2222
import com.google.appengine.api.blobstore.RangeFormatException;
2323
import com.google.appengine.tools.development.ApiProxyLocal;
24+
import com.google.common.flogger.GoogleLogger;
2425
import com.google.common.io.Closeables;
2526
import java.io.IOException;
2627
import java.io.InputStream;
2728
import java.io.OutputStream;
28-
import java.util.logging.Logger;
2929
import javax.servlet.Filter;
3030
import javax.servlet.FilterChain;
3131
import javax.servlet.FilterConfig;
@@ -45,8 +45,7 @@
4545
*
4646
*/
4747
public final class ServeBlobFilter implements Filter {
48-
private static final Logger logger = Logger.getLogger(
49-
ServeBlobFilter.class.getName());
48+
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
5049

5150
static final String SERVE_HEADER = "X-AppEngine-BlobKey";
5251
static final String BLOB_RANGE_HEADER = "X-AppEngine-BlobRange";
@@ -152,7 +151,7 @@ private void serveBlob(BlobKey blobKey,
152151
HttpServletResponse response)
153152
throws IOException {
154153
if (response.isCommitted()) {
155-
logger.severe("Asked to send blob " + blobKey + " but response was already committed.");
154+
logger.atSevere().log("Asked to send blob %s but response was already committed.", blobKey);
156155
return;
157156
}
158157

@@ -163,15 +162,15 @@ private void serveBlob(BlobKey blobKey,
163162
blobInfo = blobInfoStorage.loadGsFileInfo(blobKey);
164163
}
165164
if (blobInfo == null) {
166-
logger.severe("Could not find blob: " + blobKey);
165+
logger.atSevere().log("Could not find blob: %s", blobKey);
167166
response.sendError(HttpServletResponse.SC_NOT_FOUND);
168167
return;
169168
}
170169

171170
// And the blob missing from storage is redundant (although for file
172171
// storage could happen if the file was deleted).
173172
if (!getBlobStorage().hasBlob(blobKey)) {
174-
logger.severe("Blob " + blobKey + " missing. Did you delete the file?");
173+
logger.atSevere().log("Blob %s missing. Did you delete the file?", blobKey);
175174
response.sendError(HttpServletResponse.SC_NOT_FOUND);
176175
return;
177176
}

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/UploadBlobServlet.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.base.Ascii;
2727
import com.google.common.collect.ImmutableList;
2828
import com.google.common.collect.Maps;
29+
import com.google.common.flogger.GoogleLogger;
2930
import com.google.common.io.Closeables;
3031
// <internal24>
3132
import java.io.BufferedReader;
@@ -47,8 +48,6 @@
4748
import java.util.List;
4849
import java.util.Locale;
4950
import java.util.Map;
50-
import java.util.logging.Level;
51-
import java.util.logging.Logger;
5251
import javax.activation.DataHandler;
5352
import javax.activation.DataSource;
5453
import javax.mail.BodyPart;
@@ -84,8 +83,7 @@
8483
*/
8584
public final class UploadBlobServlet extends HttpServlet {
8685
private static final long serialVersionUID = -813190429684600745L;
87-
private static final Logger logger =
88-
Logger.getLogger(UploadBlobServlet.class.getName());
86+
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
8987

9088
static final String UPLOAD_HEADER = "X-AppEngine-BlobUpload";
9189

@@ -186,10 +184,10 @@ private void handleUpload(final HttpServletRequest req, HttpServletResponse resp
186184
totalSize += size;
187185
largestBlobSize = Math.max(size, largestBlobSize);
188186
} else {
189-
logger.log(Level.WARNING,
190-
"Unable to determine size of upload part named " +
191-
part.getFileName() + "." +
192-
" Upload limit checks may not be accurate.");
187+
logger.atWarning().log(
188+
"Unable to determine size of upload part named %s. Upload limit checks may not be"
189+
+ " accurate.",
190+
part.getFileName());
193191
}
194192
}
195193
}

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/jakarta/ServeBlobFilter.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.appengine.api.blobstore.dev.BlobStorageFactory;
2626
import com.google.appengine.api.blobstore.dev.LocalBlobstoreService;
2727
import com.google.appengine.tools.development.ApiProxyLocal;
28+
import com.google.common.flogger.GoogleLogger;
2829
import com.google.common.io.Closeables;
2930
import jakarta.servlet.Filter;
3031
import jakarta.servlet.FilterChain;
@@ -38,7 +39,6 @@
3839
import java.io.IOException;
3940
import java.io.InputStream;
4041
import java.io.OutputStream;
41-
import java.util.logging.Logger;
4242

4343
/**
4444
* {@code ServeBlobFilter} implements the ability to serve a blob in
@@ -49,8 +49,7 @@
4949
*
5050
*/
5151
public final class ServeBlobFilter implements Filter {
52-
private static final Logger logger = Logger.getLogger(
53-
ServeBlobFilter.class.getName());
52+
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
5453

5554
static final String SERVE_HEADER = "X-AppEngine-BlobKey";
5655
static final String BLOB_RANGE_HEADER = "X-AppEngine-BlobRange";
@@ -156,7 +155,7 @@ private void serveBlob(BlobKey blobKey,
156155
HttpServletResponse response)
157156
throws IOException {
158157
if (response.isCommitted()) {
159-
logger.severe("Asked to send blob " + blobKey + " but response was already committed.");
158+
logger.atSevere().log("Asked to send blob %s but response was already committed.", blobKey);
160159
return;
161160
}
162161

@@ -167,15 +166,15 @@ private void serveBlob(BlobKey blobKey,
167166
blobInfo = blobInfoStorage.loadGsFileInfo(blobKey);
168167
}
169168
if (blobInfo == null) {
170-
logger.severe("Could not find blob: " + blobKey);
169+
logger.atSevere().log("Could not find blob: %s", blobKey);
171170
response.sendError(HttpServletResponse.SC_NOT_FOUND);
172171
return;
173172
}
174173

175174
// And the blob missing from storage is redundant (although for file
176175
// storage could happen if the file was deleted).
177176
if (!getBlobStorage().hasBlob(blobKey)) {
178-
logger.severe("Blob " + blobKey + " missing. Did you delete the file?");
177+
logger.atSevere().log("Blob %s missing. Did you delete the file?", blobKey);
179178
response.sendError(HttpServletResponse.SC_NOT_FOUND);
180179
return;
181180
}

api_dev/src/main/java/com/google/appengine/api/blobstore/dev/jakarta/UploadBlobServlet.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.apphosting.utils.servlet.jakarta.MultipartMimeUtils;
3232
import com.google.common.base.Ascii;
3333
import com.google.common.collect.ImmutableList;
34+
import com.google.common.flogger.GoogleLogger;
3435
import com.google.common.io.Closeables;
3536
// <internal24>
3637
import jakarta.servlet.ReadListener;
@@ -58,8 +59,6 @@
5859
import java.util.HashMap;
5960
import java.util.List;
6061
import java.util.Map;
61-
import java.util.logging.Level;
62-
import java.util.logging.Logger;
6362
import javax.activation.DataHandler;
6463
import javax.activation.DataSource;
6564
import javax.mail.BodyPart;
@@ -88,8 +87,7 @@
8887
*/
8988
public final class UploadBlobServlet extends HttpServlet {
9089
private static final long serialVersionUID = -813190429684600745L;
91-
private static final Logger logger =
92-
Logger.getLogger(UploadBlobServlet.class.getName());
90+
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
9391

9492
static final String UPLOAD_HEADER = "X-AppEngine-BlobUpload";
9593

@@ -190,10 +188,10 @@ private void handleUpload(final HttpServletRequest req, HttpServletResponse resp
190188
totalSize += size;
191189
largestBlobSize = Math.max(size, largestBlobSize);
192190
} else {
193-
logger.log(Level.WARNING,
194-
"Unable to determine size of upload part named " +
195-
part.getFileName() + "." +
196-
" Upload limit checks may not be accurate.");
191+
logger.atWarning().log(
192+
"Unable to determine size of upload part named %s. Upload limit checks may not be"
193+
+ " accurate.",
194+
part.getFileName());
197195
}
198196
}
199197
}

0 commit comments

Comments
 (0)