Skip to content

Commit

Permalink
tidy up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo van Kraay committed Aug 15, 2022
1 parent 5754fb9 commit de3d39e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void main(String[] args) {
logger.info("Demo complete, please hold while resources are released");
} catch (Exception e) {
e.printStackTrace();
logger.error(String.format("Cosmos getStarted failed with %s", e));
logger.error("Cosmos getStarted failed with {}", e);
} finally {
logger.info("Closing the client");
p.shutdown();
Expand All @@ -67,7 +67,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {

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

// Create async client
// Create sync client
client = new CosmosClientBuilder()
.endpoint(AccountSettings.HOST)
.key(AccountSettings.MASTER_KEY)
Expand Down

0 comments on commit de3d39e

Please sign in to comment.