Skip to content

Commit de3d39e

Browse files
author
Theo van Kraay
committed
tidy up logging
1 parent 5754fb9 commit de3d39e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/main/java/com/azure/cosmos/examples/autoscalecontainercrud/async/AutoscaleContainerCRUDQuickstartAsync.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void main(String[] args) {
5656
logger.info("Demo complete, please hold while resources are released");
5757
} catch (Exception e) {
5858
e.printStackTrace();
59-
logger.error(String.format("Cosmos getStarted failed with %s", e));
59+
logger.error("Cosmos getStarted failed with {}", e);
6060
} finally {
6161
logger.info("Closing the client");
6262
p.shutdown();
@@ -67,7 +67,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {
6767

6868
logger.info("Using Azure Cosmos DB endpoint: " + AccountSettings.HOST);
6969

70-
// Create sync client
70+
// Create async client
7171
client = new CosmosClientBuilder()
7272
.endpoint(AccountSettings.HOST)
7373
.key(AccountSettings.MASTER_KEY)
@@ -88,7 +88,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {
8888

8989
// Database Create
9090
private void createDatabaseIfNotExists() throws Exception {
91-
logger.info("Create database " + databaseName + " if not exists...");
91+
logger.info("Create database {} if not exists...", databaseName);
9292

9393
// Create database if not exists
9494
CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists(databaseName).block();
@@ -99,7 +99,7 @@ private void createDatabaseIfNotExists() throws Exception {
9999

100100
// Container create
101101
private void createContainerIfNotExists() throws Exception {
102-
logger.info("Create autoscale container " + containerName + " if not exists.");
102+
logger.info("Create autoscale container {} if not exists.", containerName);
103103

104104
// Container and autoscale throughput settings
105105
CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties(containerName, "/lastName");
@@ -115,7 +115,7 @@ private void createContainerIfNotExists() throws Exception {
115115

116116
// Update container throughput
117117
private void updateContainerThroughput() throws Exception {
118-
logger.info("Update autoscale max throughput for container " + containerName + ".");
118+
logger.info("Update autoscale max throughput for container {}.", containerName);
119119

120120
// Change the autoscale max throughput (RU/s)
121121
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(8000)).block();
@@ -138,7 +138,7 @@ private void readContainerThroughput() throws Exception {
138138

139139
// Container read
140140
private void readContainerById() throws Exception {
141-
logger.info("Read container " + containerName + " by ID.");
141+
logger.info("Read container {} by ID.", containerName);
142142

143143
// Read container by ID
144144
container = database.getContainer(containerName);
@@ -148,17 +148,15 @@ private void readContainerById() throws Exception {
148148

149149
// Container read all
150150
private void readAllContainers() throws Exception {
151-
logger.info("Read all containers in database " + databaseName + ".");
151+
logger.info("Read all containers in database {}.", databaseName);
152152

153153
// Read all containers in the account
154154
CosmosPagedFlux<CosmosContainerProperties> containers = database.readAllContainers();
155155

156156
// Print
157157
String msg="Listing containers in database:\n";
158158
containers.byPage(100).flatMap(readAllContainersResponse -> {
159-
logger.info("read " +
160-
readAllContainersResponse.getResults().size() + " containers(s)"
161-
+ " with request charge of " + readAllContainersResponse.getRequestCharge());
159+
logger.info("read {} containers(s) with request charge of {}", readAllContainersResponse.getResults().size(),readAllContainersResponse.getRequestCharge());
162160

163161
for (CosmosContainerProperties response : readAllContainersResponse.getResults()) {
164162
logger.info("container id: "+response.getId());
@@ -173,7 +171,7 @@ private void readAllContainers() throws Exception {
173171

174172
// Container delete
175173
private void deleteAContainer() throws Exception {
176-
logger.info("Delete container " + containerName + " by ID.");
174+
logger.info("Delete container {} by ID.", containerName);
177175

178176
// Delete container
179177
CosmosContainerResponse containerResp = database.getContainer(containerName).delete(new CosmosContainerRequestOptions()).block();
@@ -184,7 +182,7 @@ private void deleteAContainer() throws Exception {
184182

185183
// Database delete
186184
private void deleteADatabase() throws Exception {
187-
logger.info("Last step: delete database " + databaseName + " by ID.");
185+
logger.info("Last step: delete database {} by ID.", databaseName);
188186

189187
// Delete database
190188
CosmosDatabaseResponse dbResp = client.getDatabase(databaseName).delete(new CosmosDatabaseRequestOptions()).block();
@@ -203,8 +201,10 @@ private void shutdown() {
203201
logger.error("Deleting Cosmos DB resources failed, will still attempt to close the client. See stack trace below.");
204202
err.printStackTrace();
205203
}
206-
client.close();
207-
logger.info("Done with sample.");
204+
finally{
205+
client.close();
206+
logger.info("Done with sample.");
207+
}
208208
}
209209

210210
}

src/main/java/com/azure/cosmos/examples/autoscalecontainercrud/sync/AutoscaleContainerCRUDQuickstart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {
6363

6464
logger.info("Using Azure Cosmos DB endpoint: {}", AccountSettings.HOST);
6565

66-
// Create async client
66+
// Create sync client
6767
client = new CosmosClientBuilder()
6868
.endpoint(AccountSettings.HOST)
6969
.key(AccountSettings.MASTER_KEY)

0 commit comments

Comments
 (0)