{"id":38116,"date":"2016-07-25T20:14:23","date_gmt":"2016-07-25T14:44:23","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=38116"},"modified":"2016-07-25T20:43:12","modified_gmt":"2016-07-25T15:13:12","slug":"logging-with-spring-aop-and-custom-annotations-in-java-application","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/logging-with-spring-aop-and-custom-annotations-in-java-application\/","title":{"rendered":"Logging with Spring AOP and Custom Annotations In JAVA Application"},"content":{"rendered":"<p>Whenever i am working on development of any application I want to log every execution of a method, seeing what arguments it receives, what it returns for easy debugging and how much time every execution take.<\/p>\n<p>So we have created a utility based on Spring AOP and here we will see how we can use it in our projects.<br \/>\n<code><br \/>\n@RestController<br \/>\n@Loggable<br \/>\npublic class HomeController {<\/p>\n<p>\/\/action<\/p>\n<p>}<br \/>\n<\/code><br \/>\nThe @Loggable annotation have option to log method parameter and results. By default both option are true you can disable these option by setting attributes.<br \/>\n<code><br \/>\n@Loggable(params = true,result = false)<br \/>\n<\/code><br \/>\nWe can override options at method level or Can mark only selected methods for logging.<br \/>\n<code><br \/>\n@Loggable(result = false)<br \/>\npublic Integer multiply(int a, int b) {<br \/>\nInteger res = a * b;<br \/>\nreturn res;<br \/>\n}<\/code><\/p>\n<p>Note: Don&#8217;t forget to set your application log level from application configuration file.<br \/>\n<code><br \/>\nlogging.level.root=debug<\/p>\n<p>  \/\/gradle dependency<br \/>\n  compile('org.springframework.boot:spring-boot-starter-aop')<br \/>\n<\/code><\/p>\n<p>download project form <a title=\"github\" href=\"https:\/\/github.com\/stayendraverma\/aop-logger\" target=\"_blank\">github<\/a> and copy log package and paste into your project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever i am working on development of any application I want to log every execution of a method, seeing what arguments it receives, what it returns for easy debugging and how much time every execution take. So we have created a utility based on Spring AOP and here we will see how we can use [&hellip;]<\/p>\n","protected":false},"author":902,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":15},"categories":[1],"tags":[4844,4841,2684],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38116"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/902"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=38116"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38116\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=38116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=38116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=38116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}