Sunday, June 13, 2021

Small tip to improve your log statements in Java

 Have a look at the code below:


Now take a look at the below log output from running the above code:


The trade type is: ‘BLOCK’ so we would expect the method to return true. However, it is returning false. It is difficult to see what is going wrong from the above log statements.  

A useful tip to improve your logging is to surround the {} in your log statements with square brackets: [] as shown underlined in red below:


When we rerun the above code with the improved log statements, it is immediately clear what the issue is (trailing white space in the trade type):


This small change to your log statements can save you a lot of time when trying to investigate why your program is not working as expected. 



No comments:

Post a Comment

My answers to Minna no Nihongo Lesson 47 Renshuu B

My answers to Minna no Nihongo Lesson 47 Renshuu B If you see any mistakes, please let me know 1) 1.     昨日の新聞によると、日本の女性は世界で一番長生きするそうで...