Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit da2bb00

Browse files
author
Theo van Kraay
committed
tidy up logging and flow
1 parent 3698df7 commit da2bb00

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/main/java/com/azure/cosmos/examples/autoscaledatabasecrud/async/AutoscaleDatabaseCRUDQuickstartAsync.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void main(String[] args) {
5050
logger.info("Demo complete, please hold while resources are released");
5151
} catch (Exception e) {
5252
e.printStackTrace();
53-
logger.error(String.format("Cosmos getStarted failed with %s", e));
53+
logger.error("Cosmos getStarted failed with {}", e);
5454
} finally {
5555
logger.info("Closing the client");
5656
p.shutdown();
@@ -59,9 +59,9 @@ public static void main(String[] args) {
5959

6060
private void autoscaleDatabaseCRUDDemo() throws Exception {
6161

62-
logger.info("Using Azure Cosmos DB endpoint: " + AccountSettings.HOST);
62+
logger.info("Using Azure Cosmos DB endpoint: {}", AccountSettings.HOST);
6363

64-
// Create sync client
64+
// Create async client
6565
client = new CosmosClientBuilder()
6666
.endpoint(AccountSettings.HOST)
6767
.key(AccountSettings.MASTER_KEY)
@@ -79,7 +79,7 @@ private void autoscaleDatabaseCRUDDemo() throws Exception {
7979

8080
// Database Create
8181
private void createDatabaseIfNotExists() throws Exception {
82-
logger.info("Create database " + databaseName + " if not exists...");
82+
logger.info("Create database {} if not exists...", databaseName);
8383

8484
// Autoscale throughput settings
8585
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(4000); //Set autoscale max RU/s
@@ -95,7 +95,7 @@ private void createDatabaseIfNotExists() throws Exception {
9595

9696
// Database read
9797
private void readDatabaseById() throws Exception {
98-
logger.info("Read database " + databaseName + " by ID.");
98+
logger.info("Read database {} by ID.", databaseName);
9999

100100
// Read database by ID
101101
database = client.getDatabase(databaseName);
@@ -113,12 +113,10 @@ private void readAllDatabases() throws Exception {
113113
// Print
114114
String msg="Listing databases in account:\n";
115115
databases.byPage(100).flatMap(readAllDatabasesResponse -> {
116-
logger.info("read " +
117-
readAllDatabasesResponse.getResults().size() + " database(s)"
118-
+ " with request charge of " + readAllDatabasesResponse.getRequestCharge());
116+
logger.info("read {} database(s) with request charge of {}", readAllDatabasesResponse.getResults().size(), readAllDatabasesResponse.getRequestCharge());
119117

120118
for (CosmosDatabaseProperties response : readAllDatabasesResponse.getResults()) {
121-
logger.info("database id: "+response.getId());
119+
logger.info("database id: {}",response.getId());
122120
//Got a page of query result with
123121
}
124122
return Flux.empty();
@@ -130,7 +128,7 @@ private void readAllDatabases() throws Exception {
130128

131129
// Database delete
132130
private void deleteADatabase() throws Exception {
133-
logger.info("Last step: delete database " + databaseName + " by ID.");
131+
logger.info("Last step: delete database {} by ID.", databaseName);
134132

135133
// Delete database
136134
CosmosDatabaseResponse dbResp = client.getDatabase(databaseName).delete(new CosmosDatabaseRequestOptions()).block();
@@ -148,8 +146,9 @@ private void shutdown() {
148146
logger.error("Deleting Cosmos DB resources failed, will still attempt to close the client. See stack trace below.");
149147
err.printStackTrace();
150148
}
151-
client.close();
152-
logger.info("Done with sample.");
149+
finally{
150+
client.close();
151+
logger.info("Done with sample.");
152+
}
153153
}
154-
155154
}

0 commit comments

Comments
 (0)