{"id":29477,"date":"2022-11-25T18:32:26","date_gmt":"2022-11-25T13:02:26","guid":{"rendered":"https:\/\/blazeclan.com\/benefits-of-logging-in-application-development\/"},"modified":"2023-03-10T12:16:16","modified_gmt":"2023-03-10T06:46:16","slug":"benefits-of-logging-in-application-development","status":"publish","type":"post","link":"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/","title":{"rendered":"Benefits of Logging in Application Development"},"content":{"rendered":"<p>As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues&nbsp;or for simply tracking events. In the&nbsp;production environment, we can&#8217;t debug issues without proper log files as they become the only source of information to debug some intermittent or unexpected errors.<\/p>\n<h2><strong>Advantages of Using Loggers<\/strong><\/h2>\n<ul>\n<li>Appenders, Rolling files, new log files when a size limit is reached<\/li>\n<li>Choice of contextual information which is crucial.<\/li>\n<li>Which class<\/li>\n<li>What timestamp<\/li>\n<li>Which user<\/li>\n<li>Filename<\/li>\n<li>Right formatting<\/li>\n<li>Separate log files for different components.<\/li>\n<li>Log levels(like DEBUG, WARN, INFO) which can be very handy when you want to track the path followed by your program or log queries, etc.<\/li>\n<\/ul>\n<p>As a matter of fact, all this functionality comes for free without recompiling the code. Moreover, there are&nbsp;other Pros&nbsp;as well when we deploy microservices in the cloud (AWS). If you are using CloudWatch, you can filter logs using contextual information provided by loggers. With centralized logging in place, it becomes imperative to use this mechanism.<\/p>\n<h2><strong>Common Issues When Using Loggers<\/strong><\/h2>\n<p>Keeping aside the case where we choose&nbsp;not to add logs, a bad code day for me already and is a completely different scenario altogether. However, the following steps can be followed for:<\/p>\n<h2><strong>Logging Large Objects or Collections<\/strong><\/h2>\n<pre>Java Code\nlogger.error(\"results\"+resultset)\nor\nlogger.error(\"\nusermap\n\"+map)<\/pre>\n<p>While this may look&nbsp;simple especially when we are developing and not testing with large amounts of data, however, above two logging statements it would do just fine. In production, imagine a resultset with 100,000 records or Map with 200,000 entries, even worse what if the data is hierarchical? This would be fatal!<\/p>\n<h2><strong>Logging Sensitive Data<\/strong><\/h2>\n<p>While we use loggers, we can be&nbsp;carefree about what to log information like:<\/p>\n<ul>\n<li>User personal data hidden in <a href=\"https:\/\/www.geeksforgeeks.org\/pojo-vs-java-beans\/\">POJOS or DB query results<\/a><\/li>\n<li>User request data which may contain passwords<\/li>\n<li>Financial or credit card information<\/li>\n<\/ul>\n<p>Its very easy to overlook this while doing development as some of this data is either not available or sometimes is not created yet. <strong>Performance Hits while Logging<\/strong> Many of us end up writing a simple log statement as the following:<\/p>\n<pre>Java code\nlogger.debug(\"mydata\"+map)<\/pre>\n<p>While we are logging it as &#8216;DEBUG&#8217; so as we may think, above logging has a big performance impact depending upon what kind of object you are logging. If Map is composed of complex objects, Java ends up calling to String() on every single element even though it will not log this data because log level is set to &#8220;ERROR&#8221;. To avoid this performance issue, it is sometimes recommended to use a pre-check for existing allowed logging level like this:<\/p>\n<pre>Java code\nif (logger.isDebugEnabled()) {\nlogger.debug(\"My data: \" + map);\n}<\/pre>\n<p>At times, this technique helps but it also clutters the code when you have too many logging statements. So instead, you should use the following code.<\/p>\n<pre>Java code\nlogger.debug(\"My data is : {} \", map);<\/pre>\n<p>This ensures the map elements are not iterated for String expression evaluation until the &#8220;DEBUG&#8221; level logging is enabled. This feature is available in the latest Log4j libraries.<\/p>\n<p><strong>What Next?<\/strong><\/p>\n<p>This write-up scratches the surface on the best practices for logging and it rightly intends to highlight why it is important. Choice of writing a good code is primarily a matter of intent and a habit. Moreover, we at BlazeClan adhere to great code quality practices as debugging in the cloud becomes difficult if you are not doing proper logging in your application. Stay tuned for my next post on logging on AWS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues&nbsp;or for simply tracking events. In the&nbsp;production environment, we can&#8217;t debug issues without proper log files as they become the only source of information to debug some [&hellip;]<\/p>\n","protected":false},"author":192,"featured_media":18723,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[913,1943],"tags":[1849,2342,1426,2343,2344],"class_list":["post-29477","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-asean","category-tech-asean","tag-aws-asean","tag-aws-logs-asean","tag-cloud-asean","tag-cloudwatch-asean","tag-coding-best-practices-asean"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Benefits of Logging in Application Development - Blazeclan<\/title>\n<meta name=\"description\" content=\"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Benefits of Logging in Application Development - Blazeclan\" \/>\n<meta property=\"og:description\" content=\"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/\" \/>\n<meta property=\"og:site_name\" content=\"Blazeclan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/blazeclan.hq\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-25T13:02:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-10T06:46:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1650\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Team Blazeclan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@blazeclan_hq\" \/>\n<meta name=\"twitter:site\" content=\"@blazeclan_hq\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Team Blazeclan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/\"},\"author\":{\"name\":\"Team Blazeclan\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/779910eccddff4a1ea6663b6bfb271e8\"},\"headline\":\"Benefits of Logging in Application Development\",\"datePublished\":\"2022-11-25T13:02:26+00:00\",\"dateModified\":\"2023-03-10T06:46:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/\"},\"wordCount\":580,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/#organization\"},\"image\":{\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png\",\"keywords\":[\"AWS\",\"AWS Logs\",\"Cloud\",\"CloudWatch\",\"Coding Best Practices\"],\"articleSection\":[\"Cloud\",\"Tech\"],\"inLanguage\":\"ASEAN\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/\",\"url\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/\",\"name\":\"Benefits of Logging in Application Development - Blazeclan\",\"isPartOf\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png\",\"datePublished\":\"2022-11-25T13:02:26+00:00\",\"dateModified\":\"2023-03-10T06:46:16+00:00\",\"description\":\"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues\",\"breadcrumb\":{\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#breadcrumb\"},\"inLanguage\":\"ASEAN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ASEAN\",\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage\",\"url\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png\",\"contentUrl\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png\",\"width\":1650,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blazeclan.com\/asean\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Benefits of Logging in Application Development\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#website\",\"url\":\"https:\/\/blazeclan.com\/asean\/\",\"name\":\"Blazeclan\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blazeclan.com\/asean\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ASEAN\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#organization\",\"name\":\"Blazeclan\",\"url\":\"https:\/\/blazeclan.com\/asean\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ASEAN\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2024\/10\/ITCI-Blazeclan_logo.svg\",\"contentUrl\":\"https:\/\/blazeclan.com\/wp-content\/uploads\/2024\/10\/ITCI-Blazeclan_logo.svg\",\"caption\":\"Blazeclan\"},\"image\":{\"@id\":\"https:\/\/blazeclan.com\/asean\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/blazeclan.hq\/\",\"https:\/\/x.com\/blazeclan_hq\",\"https:\/\/www.instagram.com\/blazeclantechnologies\/\",\"https:\/\/www.linkedin.com\/company\/blazeclan-technologies\/\",\"https:\/\/www.youtube.com\/channel\/UCCKF4Lcbtus-pUoZr7Lxrow\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/779910eccddff4a1ea6663b6bfb271e8\",\"name\":\"Team Blazeclan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ASEAN\",\"@id\":\"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a43c1fa01bb3c7e839254c9084bf11ed422d7e633231f9e935096045af416ba2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a43c1fa01bb3c7e839254c9084bf11ed422d7e633231f9e935096045af416ba2?s=96&d=mm&r=g\",\"caption\":\"Team Blazeclan\"},\"sameAs\":[\"http:\/\/localhost\/ps-local-wp\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Benefits of Logging in Application Development - Blazeclan","description":"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/","og_locale":"en_US","og_type":"article","og_title":"Benefits of Logging in Application Development - Blazeclan","og_description":"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues","og_url":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/","og_site_name":"Blazeclan","article_publisher":"https:\/\/www.facebook.com\/blazeclan.hq\/","article_published_time":"2022-11-25T13:02:26+00:00","article_modified_time":"2023-03-10T06:46:16+00:00","og_image":[{"width":1650,"height":680,"url":"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png","type":"image\/png"}],"author":"Team Blazeclan","twitter_card":"summary_large_image","twitter_creator":"@blazeclan_hq","twitter_site":"@blazeclan_hq","twitter_misc":{"Written by":"Team Blazeclan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#article","isPartOf":{"@id":"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/"},"author":{"name":"Team Blazeclan","@id":"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/779910eccddff4a1ea6663b6bfb271e8"},"headline":"Benefits of Logging in Application Development","datePublished":"2022-11-25T13:02:26+00:00","dateModified":"2023-03-10T06:46:16+00:00","mainEntityOfPage":{"@id":"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/"},"wordCount":580,"commentCount":0,"publisher":{"@id":"https:\/\/blazeclan.com\/asean\/#organization"},"image":{"@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage"},"thumbnailUrl":"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png","keywords":["AWS","AWS Logs","Cloud","CloudWatch","Coding Best Practices"],"articleSection":["Cloud","Tech"],"inLanguage":"ASEAN","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blazeclan.com\/asean\/blog\/benefits-of-logging-in-application-development\/","url":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/","name":"Benefits of Logging in Application Development - Blazeclan","isPartOf":{"@id":"https:\/\/blazeclan.com\/asean\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage"},"image":{"@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage"},"thumbnailUrl":"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png","datePublished":"2022-11-25T13:02:26+00:00","dateModified":"2023-03-10T06:46:16+00:00","description":"As developers, we all should know the need for logging the code we create. Logging is essential to understand the behaviour of the application and to debug unexpected issues","breadcrumb":{"@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#breadcrumb"},"inLanguage":"ASEAN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/"]}]},{"@type":"ImageObject","inLanguage":"ASEAN","@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#primaryimage","url":"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png","contentUrl":"https:\/\/blazeclan.com\/wp-content\/uploads\/2018\/07\/Webp-net-compress-image-3.png","width":1650,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/blazeclan.com\/blog\/benefits-of-logging-in-application-development\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blazeclan.com\/asean\/"},{"@type":"ListItem","position":2,"name":"Benefits of Logging in Application Development"}]},{"@type":"WebSite","@id":"https:\/\/blazeclan.com\/asean\/#website","url":"https:\/\/blazeclan.com\/asean\/","name":"Blazeclan","description":"","publisher":{"@id":"https:\/\/blazeclan.com\/asean\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blazeclan.com\/asean\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ASEAN"},{"@type":"Organization","@id":"https:\/\/blazeclan.com\/asean\/#organization","name":"Blazeclan","url":"https:\/\/blazeclan.com\/asean\/","logo":{"@type":"ImageObject","inLanguage":"ASEAN","@id":"https:\/\/blazeclan.com\/asean\/#\/schema\/logo\/image\/","url":"https:\/\/blazeclan.com\/wp-content\/uploads\/2024\/10\/ITCI-Blazeclan_logo.svg","contentUrl":"https:\/\/blazeclan.com\/wp-content\/uploads\/2024\/10\/ITCI-Blazeclan_logo.svg","caption":"Blazeclan"},"image":{"@id":"https:\/\/blazeclan.com\/asean\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/blazeclan.hq\/","https:\/\/x.com\/blazeclan_hq","https:\/\/www.instagram.com\/blazeclantechnologies\/","https:\/\/www.linkedin.com\/company\/blazeclan-technologies\/","https:\/\/www.youtube.com\/channel\/UCCKF4Lcbtus-pUoZr7Lxrow"]},{"@type":"Person","@id":"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/779910eccddff4a1ea6663b6bfb271e8","name":"Team Blazeclan","image":{"@type":"ImageObject","inLanguage":"ASEAN","@id":"https:\/\/blazeclan.com\/asean\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a43c1fa01bb3c7e839254c9084bf11ed422d7e633231f9e935096045af416ba2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a43c1fa01bb3c7e839254c9084bf11ed422d7e633231f9e935096045af416ba2?s=96&d=mm&r=g","caption":"Team Blazeclan"},"sameAs":["http:\/\/localhost\/ps-local-wp"]}]}},"_links":{"self":[{"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/posts\/29477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/users\/192"}],"replies":[{"embeddable":true,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/comments?post=29477"}],"version-history":[{"count":0,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/posts\/29477\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/media\/18723"}],"wp:attachment":[{"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/media?parent=29477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/categories?post=29477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blazeclan.com\/asean\/wp-json\/wp\/v2\/tags?post=29477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}