@@ -55,14 +55,14 @@ public static void main(String[] args) {
5555 AsyncMain p = new AsyncMain ();
5656
5757 try {
58- System . out . println ("Starting ASYNC main" );
58+ logger . info ("Starting ASYNC main" );
5959 p .getStartedDemo ();
60- System . out . println ("Demo complete, please hold while resources are released" );
60+ logger . info ("Demo complete, please hold while resources are released" );
6161 } catch (Exception e ) {
6262 e .printStackTrace ();
63- System . err . println ( String . format ( "Cosmos getStarted failed with %s" , e ) );
63+ logger . error ( "Cosmos getStarted failed with %s" , e );
6464 } finally {
65- System . out . println ("Closing the client" );
65+ logger . info ("Closing the client" );
6666 p .close ();
6767 }
6868 System .exit (0 );
@@ -71,7 +71,7 @@ public static void main(String[] args) {
7171 // </Main>
7272
7373 private void getStartedDemo () throws Exception {
74- System . out . println ("Using Azure Cosmos DB endpoint: " + AccountSettings .HOST );
74+ logger . info ("Using Azure Cosmos DB endpoint: {}" , AccountSettings .HOST );
7575
7676 // Create async client
7777 // <CreateAsyncClient>
@@ -109,29 +109,29 @@ private void getStartedDemo() throws Exception {
109109 johnsonFamilyItem ,
110110 smithFamilyItem );
111111
112- System . out . println ("Reading items." );
112+ logger . info ("Reading items." );
113113 readItems (familiesToCreate );
114114
115- System . out . println ("Querying items." );
115+ logger . info ("Querying items." );
116116 queryItems ();
117117 }
118118
119119 private void createDatabaseIfNotExists () throws Exception {
120- System . out . println ("Create database " + databaseName + " if not exists." );
120+ logger . info ("Create database {} if not exists." , databaseName );
121121
122122 // Create database if not exists
123123 // <CreateDatabaseIfNotExists>
124124 Mono <CosmosDatabaseResponse > databaseResponseMono = client .createDatabaseIfNotExists (databaseName );
125125 databaseResponseMono .flatMap (databaseResponse -> {
126126 database = client .getDatabase (databaseResponse .getProperties ().getId ());
127- System . out . println ("Checking database " + database .getId () + " completed! \n " );
127+ logger . info ("Checking database {} completed! \n " , database .getId ());
128128 return Mono .empty ();
129129 }).block ();
130130 // </CreateDatabaseIfNotExists>
131131 }
132132
133133 private void createContainerIfNotExists () throws Exception {
134- System . out . println ("Create container " + containerName + " if not exists." );
134+ logger . info ("Create container {} if not exists." , containerName );
135135
136136 // Create container if not exists
137137 // <CreateContainerIfNotExists>
@@ -142,7 +142,7 @@ private void createContainerIfNotExists() throws Exception {
142142 // Create container with 400 RU/s
143143 containerResponseMono .flatMap (containerResponse -> {
144144 container = database .getContainer (containerResponse .getProperties ().getId ());
145- System . out . println ("Checking container " + container .getId () + " completed! \n " );
145+ logger . info ("Checking container {} completed! \n " , container .getId ());
146146 return Mono .empty ();
147147 }).block ();
148148
@@ -160,25 +160,25 @@ private void createFamilies(Flux<Family> families) throws Exception {
160160 return container .createItem (family );
161161 }) //Flux of item request responses
162162 .flatMap (itemResponse -> {
163- logger .info (String . format ( "Created item with request charge of %.2f within" +
164- " duration %s " ,
165- itemResponse .getRequestCharge (), itemResponse .getDuration ())) ;
166- logger .info (String . format ( "Item ID: %s \n " , itemResponse .getItem ().getId () ));
163+ logger .info ("Created item with request charge of {}} within" +
164+ " duration {} " ,
165+ itemResponse .getRequestCharge (), itemResponse .getDuration ());
166+ logger .info ("Item ID: {} \n " , itemResponse .getItem ().getId ());
167167 return Mono .just (itemResponse .getRequestCharge ());
168168 }) //Flux of request charges
169169 .reduce (0.0 ,
170170 (charge_n , charge_nplus1 ) -> charge_n + charge_nplus1
171171 ) //Mono of total charge - there will be only one item in this stream
172172 .block (); //Preserve the total charge and print aggregate charge/item count stats.
173173
174- logger .info (String . format ( "Created items with total request charge of %.2f \n " , charge ) );
174+ logger .info ("Created items with total request charge of {} \n " , charge );
175175
176176 } catch (Exception err ) {
177177 if (err instanceof CosmosException ) {
178178 //Client-specific errors
179179 CosmosException cerr = (CosmosException ) err ;
180180 cerr .printStackTrace ();
181- logger .error (String . format ( "Read Item failed with %s\n " , cerr ) );
181+ logger .error ("Read Item failed with %s\n " , cerr );
182182 } else {
183183 //General errors
184184 err .printStackTrace ();
@@ -201,8 +201,8 @@ private void readItems(Flux<Family> familiesToCreate) {
201201 }).flatMap (itemResponse -> {
202202 double requestCharge = itemResponse .getRequestCharge ();
203203 Duration requestLatency = itemResponse .getDuration ();
204- logger .info (String . format ( "Item successfully read with id %s with a charge of %.2f and within duration %s " ,
205- itemResponse .getItem ().getId (), requestCharge , requestLatency )) ;
204+ logger .info ("Item successfully read with id {} with a charge of {} and within duration {} " ,
205+ itemResponse .getItem ().getId (), requestCharge , requestLatency );
206206 return Flux .empty ();
207207 }).blockLast ();
208208
@@ -211,7 +211,7 @@ private void readItems(Flux<Family> familiesToCreate) {
211211 //Client-specific errors
212212 CosmosException cerr = (CosmosException ) err ;
213213 cerr .printStackTrace ();
214- logger .error (String . format ( "Read Item failed with %s \n " , cerr ) );
214+ logger .error ("Read Item failed with {} \n " , cerr );
215215 } else {
216216 //General errors
217217 err .printStackTrace ();
@@ -238,11 +238,10 @@ private void queryItems() {
238238 try {
239239
240240 pagedFluxResponse .byPage (preferredPageSize ).flatMap (fluxResponse -> {
241- logger .info ("Got a page of query result with " +
242- fluxResponse .getResults ().size () + " items(s)"
243- + " and request charge of " + fluxResponse .getRequestCharge ());
241+ logger .info ("Got a page of query result with {} items(s)"
242+ + " and request charge of {}" , fluxResponse .getResults ().size (), fluxResponse .getRequestCharge ());
244243
245- logger .info ("Item Ids " + fluxResponse
244+ logger .info ("Item Ids {}" , fluxResponse
246245 .getResults ()
247246 .stream ()
248247 .map (Family ::getId )
@@ -256,7 +255,7 @@ private void queryItems() {
256255 //Client-specific errors
257256 CosmosException cerr = (CosmosException ) err ;
258257 cerr .printStackTrace ();
259- logger .error (String . format ( "Read Item failed with %s\n " , cerr ) );
258+ logger .error ("Read Item failed with %s\n " , cerr );
260259 } else {
261260 //General errors
262261 err .printStackTrace ();
0 commit comments