{"id":6713,"date":"2012-09-05T10:31:19","date_gmt":"2012-09-05T05:01:19","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=6713"},"modified":"2016-12-19T15:16:41","modified_gmt":"2016-12-19T09:46:41","slug":"log4j-creating-different-log-files-every-day","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/log4j-creating-different-log-files-every-day\/","title":{"rendered":"Log4j: Creating Different Log Files Every Day"},"content":{"rendered":"<p>To avoid getting log messages in single log file we can create a new log file every day in just one step. This can be done very easily by using <strong>DailyRollingFileAppender<\/strong> instead of RollingFileAppender . We just need to add a new Log4J appenders to our configuration file (Config.groovy).<\/p>\n<p>In the following example we create a <a href=\"http:\/\/logging.apache.org\/log4j\/1.2\/apidocs\/org\/apache\/log4j\/DailyRollingFileAppender.html\">DailyRollingFileAppender <\/a>in our configuration so each day a new log file is created and old log files are renamed with the date in the file.<\/p>\n<p>[java]<\/p>\n<p>import org.apache.log4j.DailyRollingFileAppender<\/p>\n<p>log4j = {<br \/>\n    appenders {<br \/>\n        console name: &#8216;stdout&#8217;, layout: pattern(conversionPattern: &#8216;%c{2} %m%n&#8217;)<br \/>\n             appender new DailyRollingFileAppender(<br \/>\n                  name: &#8216;stacktrace&#8217;,<br \/>\n                  datePattern: &quot;&#8217;.&#8217;yyyy-MM-dd&quot;,<br \/>\n                  fileName: logFilePath+&#8217;\/FileName.log&#8217;,  \/\/storage path of log file<br \/>\n                  maxFileSize:1024,<br \/>\n                  layout: pattern(conversionPattern:&#8217;%d [%t] %-5p %c{2} %x &#8211; %m%n&#8217;)<br \/>\n                )<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>For this you just need to import DailyRollingFileAppender class<\/p>\n<p>Hope this will help you. \ud83d\ude42<br \/>\nGunpreet Bedi<br \/>\ngunpreet@intelligrape.com<\/p>\n<p><a href=\"https:\/\/twitter.com\/gunpreet_ginny\">https:\/\/twitter.com\/gunpreet_ginny<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To avoid getting log messages in single log file we can create a new log file every day in just one step. This can be done very easily by using DailyRollingFileAppender instead of RollingFileAppender . We just need to add a new Log4J appenders to our configuration file (Config.groovy). In the following example we create [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":29},"categories":[7],"tags":[4840,471,869],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/6713"}],"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\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=6713"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/6713\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=6713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=6713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=6713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}