{"id":53627,"date":"2018-01-10T11:00:03","date_gmt":"2018-01-10T09:00:03","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=53627"},"modified":"2018-01-08T13:44:39","modified_gmt":"2018-01-08T11:44:39","slug":"log4j-rotation-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/","title":{"rendered":"Log4j Rotation Example"},"content":{"rendered":"<p>This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files.<\/p>\n<h2>1. Introduction<\/h2>\n<p>Log4J(<strong>Java<\/strong>) is widely used logging framework for Java. It continues to grow continuously with recent upgrade of Log4j2. We want to rotate log files to avoid log file accumulation and easily segregate logs under the log folder.<\/p>\n<p>Log4j supports logging with help of Appender and Layouts. Layout specifies the display format of the logs. Commonly used Layout for Log4j is <code>PatternLayout<\/code>. A sample pattern is\u00a0 <strong>%d [%t] %-5p (%F: %L) &#8211; %m%n. <\/strong>The format strings\u00a0 for the pattern are as follows:<\/p>\n<ul>\n<li>Date &#8211;\u00a0 Full date till micro seconds<\/li>\n<li>Thread &#8211; JVM thread logging the output<\/li>\n<li>Logging Mode &#8211; INFO\/ERROR\/DEBUG\/WARN<\/li>\n<li>Class &#8211; Java Class logging the output<\/li>\n<li>Line number &#8211; Line number in java class<\/li>\n<li>Message &#8211; The message logged<\/li>\n<li>Default line separator -\/n unless specified otherwise<\/li>\n<\/ul>\n<p><figure id=\"attachment_53670\" aria-describedby=\"caption-attachment-53670\" style=\"width: 658px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/12\/log4j_logs_example.jpg\"><img decoding=\"async\" class=\"wp-image-53670 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/12\/log4j_logs_example.jpg\" alt=\"\" width=\"658\" height=\"209\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/12\/log4j_logs_example.jpg 658w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/12\/log4j_logs_example-300x95.jpg 300w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/a><figcaption id=\"caption-attachment-53670\" class=\"wp-caption-text\">Logs Example<\/figcaption><\/figure><\/p>\n<p><strong>Appender <\/strong> delivers the log to the logging destination along with options to fine-tune the logging mechanism. Appenders generally have lifecycle configuration\u00a0 and filtering support. Filtering enables to filter messages whose logging mode does not match level configured. Two of the widely used appenders are <code>DailyRollingFileAppender<\/code> and <code>RollingFileAppender<\/code> which we will see below.<\/p>\n<h2>2. RollingFileAppender<\/h2>\n<p><code>RollingfileAppender<\/code> rotates log files based on file size. <em><strong>MaxFileSize<\/strong><\/em> indicates the maximum size of file while <em><strong>MaxBackupIndex<\/strong>\u00a0<\/em>indicates the amount of files to be kept in the log folder. A sample property file is given below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>log4j.properties<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[6,7]\">log4j.rootLogger=INFO, fileLogger\r\nlog4j.appender.fileLogger=org.apache.log4j.RollingFileAppender\r\nlog4j.appender.fileLogger.layout=org.apache.log4j.PatternLayout\r\nlog4j.appender.fileLogger.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n\r\nlog4j.appender.fileLogger.File=example.log\r\nlog4j.appender.fileLogger.MaxFileSize=1KB\r\nlog4j.appender.fileLogger.MaxBackupIndex=5\r\n<\/pre>\n<p><figure id=\"attachment_53878\" aria-describedby=\"caption-attachment-53878\" style=\"width: 339px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_maxsize_example.jpg\"><img decoding=\"async\" class=\"size-full wp-image-53878\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_maxsize_example.jpg\" alt=\"\" width=\"339\" height=\"105\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_maxsize_example.jpg 339w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_maxsize_example-300x93.jpg 300w\" sizes=\"(max-width: 339px) 100vw, 339px\" \/><\/a><figcaption id=\"caption-attachment-53878\" class=\"wp-caption-text\">RollingFileAppender Example Log<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>After 5 logs are generated, it automatically starts deleting the log files. So at any point in time, you can see a maximum of 5 logs and not more than that. Size is capped in the example at 1KB. Ideally size would be around the order of MB and is based on application needs.<\/p>\n<h2>3. DailyRollingFileAppender<\/h2>\n<p><code>DailyRollingFileAppender<\/code> rotates log files based on frequency of time allowing customization upto minute. Date Patterns allowed as part of the Appender are as follows:<\/p>\n<ul>\n<li>yyyy-MM Roll over to new log file beginning on first day of every month<\/li>\n<li>yyyy-ww Roll over to new log file beginning on first day of every week<\/li>\n<li>yyyy-MM-dd Roll over daily<\/li>\n<li>yyyy-MM-dd-a Roll over on midday and midnight<\/li>\n<li>yyyy-MM-dd-HH Roll over every hour<\/li>\n<li>yyyy-MM-dd-HH-mm Roll over every minute<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>log4j.properties<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[3,6]\">log4j.rootLogger=INFO, fileLogger\r\nlog4j.appender.fileLogger.layout=org.apache.log4j.PatternLayout\r\nlog4j.appender.fileLogger.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n\r\nlog4j.appender.fileLogger.File=example.log\r\nlog4j.appender.fileLogger=org.apache.log4j.DailyRollingFileAppender\r\nlog4j.appender.fileLogger.datePattern='.'yyyy-MM-dd-HH-mm\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_53877\" aria-describedby=\"caption-attachment-53877\" style=\"width: 291px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_minute_example.jpg\"><img decoding=\"async\" class=\"wp-image-53877 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/log4j_minute_example.jpg\" alt=\"\" width=\"291\" height=\"101\" \/><\/a><figcaption id=\"caption-attachment-53877\" class=\"wp-caption-text\">DailyRollingFileAppender Log examples<\/figcaption><\/figure><\/p>\n<p>Default date pattern is yyyy-MM-dd ie rolls every day. One downside of this appender is that old log file deletion does not happen automatically. Alternative is to implement your own custom appender.<\/p>\n<h2>4. Custom Appender<\/h2>\n<p>Custom Appender can be created by extending <code>AppenderSkeleton<\/code> class or <code>AbstractAppender<\/code>. Typically we can write our own version of <code>doAppend<\/code>. Our goal is to attach maxbackupindex capability to <code>DailyRollingFileAppender<\/code>. So it is better to extend <code>DailyRollingFileAppender<\/code> Class and provide our implementation.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Custom Appender<br \/>\n<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[1,13,20,21,26,28,29,33,34,35,36]\">package org.apache.log4j;\r\n\r\nimport java.io.File;\r\nimport java.io.IOException;\r\nimport java.util.ArrayList;\r\nimport java.util.Arrays;\r\nimport java.util.List;\r\n\r\nimport org.apache.log4j.helpers.LogLog;\r\n\r\npublic class CustomAppender extends DailyRollingFileAppender {\r\n\r\n\tprivate int maxBackupIndex;\r\n\r\n\tpublic void setMaxBackupIndex(int maxBackupIndex) {\r\n\t\tthis.maxBackupIndex = maxBackupIndex;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void rollOver() throws IOException {\r\n\t\tsuper.rollOver();\r\n\t\tFile file = new File(fileName);\r\n\t\tList&lt;String&gt; files = new ArrayList&lt;&gt;();\r\n\t\tFile[] dirFiles = new File(file.getAbsolutePath()).getParentFile().listFiles();\r\n\t\tif (dirFiles != null &amp;&amp; dirFiles.length &gt; 0) {\r\n\t\t\tArrays.sort(dirFiles, (a, b) -&gt; Long.compare(a.lastModified(), b.lastModified()));\r\n\t\t\tfor (File allFile : dirFiles) {\r\n\t\t\t\tif (allFile.getName().contains(fileName)) {\r\n\t\t\t\t\tfiles.add(allFile.getAbsolutePath());\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (files.size() &gt; maxBackupIndex+1) {\r\n\t\t\tFile deleteFile = new File(files.get(0));\r\n\t\t\tLogLog.debug(\"delete result for\"+deleteFile.getAbsolutePath()+\" is \"+deleteFile.delete());\r\n\t\t\tfiles.remove(0);\r\n\t\t}\r\n\r\n\t}\r\n}\r\n<\/pre>\n<ul>\n<li>Line 1- Package declaration is log4j. We need it to override the <code>rollover<\/code> method as visibility cannot extend in another package<\/li>\n<li>Line 13- takes an option to control the maximum files to be backed up other than current file<\/li>\n<li>Line 20,21- Override <code>rollover<\/code> method. Rollover gets called whenever a file needs to be rolledover. We call <code>DailyRollingFileAppender<\/code>&#8216;s method to finish its rollover process i.e. it renames the old file based on time and creates a new file with the filename specified<\/li>\n<li>Line 26 &#8211; Sort the file names by ascending order of created time.<\/li>\n<li>Line 28,29 &#8211;\u00a0 Filter filenames containing our log file name. In a dedicated log folder, only our log files would be there and this step might be unnecessary. It is added as caution in case the specified folder contains other files.<\/li>\n<li>Line 33,37 &#8211; delete the oldest log file and remove it from list<\/li>\n<\/ul>\n<p>This enhances <code>Dailyrollingfileappender<\/code>. Typical use case would be to keep 20 days of log and delete the rest of them.<\/p>\n<p><span style=\"text-decoration: underline\"><em>log4j.properties<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[5]\">log4j.rootLogger=INFO, fileLogger\r\nlog4j.appender.fileLogger.layout=org.apache.log4j.PatternLayout\r\nlog4j.appender.fileLogger.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n\r\nlog4j.appender.fileLogger.File=example.log\r\nlog4j.appender.fileLogger=org.apache.log4j.CustomAppender\r\nlog4j.appender.fileLogger.datePattern='.'yyyy-MM-dd-HH-mm\r\n<\/pre>\n<p>Only change is to include our Custom appender. Date Pattern usage is similar to <code>DailyRollingFileAppender<\/code> and that behaviour is extended in our custom class.<\/p>\n<h2>5. Execution Steps<\/h2>\n<ol>\n<li>Create a simple Java Project in eclipse<\/li>\n<li>Download log4j jar and include in your project by clicking on <strong>Project Properties -&gt; Java Build Path -&gt; Libraries -&gt; Add Jars<\/strong><\/li>\n<li>Copy the below java code in project<\/li>\n<li>Include a single appender in your project at a time<\/li>\n<li>Stop the running project in eclipse after 5 minutes to see various logs<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline\"><em>Java Logger Class<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[4,5,8]\">package com.jcg.examples;\r\npackage com.jcg.examples;\r\nimport org.apache.log4j.Logger;\r\npublic class LoggerMain {\r\n\tpublic static final Logger logger = Logger.getLogger(LoggerMain.class);\r\n\tpublic static void main(String[] args) {\r\n\t\twhile (true) {\r\n\t\t\tlogger.info(\"This is a test log\");\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<ul>\n<li>Line 1- Create a simple class for logging purpose<\/li>\n<li>Line 5- Creating logger for the newly created class by using factory method<\/li>\n<li>Line 8- use <code>info<\/code> method to log a message<\/li>\n<\/ul>\n<p>The whole code runs in a infinite loop and hence it is necessary to terminate manually.<\/p>\n<h2>6. Summary<\/h2>\n<p>In this tutorial we saw how to achieve log4j rotation via property files. We saw two types of existing log4j rotation appenders and a custom appender with examples.<\/p>\n<h2>7. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/01\/Log4jRotation.zip\"><strong>Log4jExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java) is widely used logging framework for Java. It continues to grow continuously with recent upgrade of Log4j2. We want to rotate log files to avoid log file accumulation and easily &hellip;<\/p>\n","protected":false},"author":148,"featured_media":13304,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[649],"tags":[],"class_list":["post-53627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-log4j"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Log4j Rotation Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Log4j Rotation Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-10T09:00:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rajagopal ParthaSarathi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PS_Rajagopal\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rajagopal ParthaSarathi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\"},\"author\":{\"name\":\"Rajagopal ParthaSarathi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85\"},\"headline\":\"Log4j Rotation Example\",\"datePublished\":\"2018-01-10T09:00:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\"},\"wordCount\":835,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg\",\"articleSection\":[\"Log4j\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\",\"name\":\"Log4j Rotation Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg\",\"datePublished\":\"2018-01-10T09:00:03+00:00\",\"description\":\"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Log4j\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/log4j\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Log4j Rotation Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85\",\"name\":\"Rajagopal ParthaSarathi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g\",\"caption\":\"Rajagopal ParthaSarathi\"},\"description\":\"Rajagopal works in software industry solving enterprise-scale problems for customers across geographies specializing in distributed platforms. He holds a masters in computer science with focus on cloud computing from Illinois Institute of Technology. His current interests include data science and distributed computing.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/rajagopalparthasarathi\/\",\"https:\/\/x.com\/PS_Rajagopal\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/rajagopal-parthasarathi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Log4j Rotation Example - Java Code Geeks","description":"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)","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:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/","og_locale":"en_US","og_type":"article","og_title":"Log4j Rotation Example - Java Code Geeks","og_description":"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-01-10T09:00:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg","type":"image\/jpeg"}],"author":"Rajagopal ParthaSarathi","twitter_card":"summary_large_image","twitter_creator":"@PS_Rajagopal","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rajagopal ParthaSarathi","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/"},"author":{"name":"Rajagopal ParthaSarathi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85"},"headline":"Log4j Rotation Example","datePublished":"2018-01-10T09:00:03+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/"},"wordCount":835,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg","articleSection":["Log4j"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/","name":"Log4j Rotation Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg","datePublished":"2018-01-10T09:00:03+00:00","description":"This article is a tutorial about log rotation in Log4j. In this tutorial, we are going to configure log4j via property files. 1. Introduction Log4J(Java)","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/apache-log4j-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/log4j\/log4j-rotation-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"Log4j","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/log4j\/"},{"@type":"ListItem","position":5,"name":"Log4j Rotation Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85","name":"Rajagopal ParthaSarathi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g","caption":"Rajagopal ParthaSarathi"},"description":"Rajagopal works in software industry solving enterprise-scale problems for customers across geographies specializing in distributed platforms. He holds a masters in computer science with focus on cloud computing from Illinois Institute of Technology. His current interests include data science and distributed computing.","sameAs":["https:\/\/www.linkedin.com\/in\/rajagopalparthasarathi\/","https:\/\/x.com\/PS_Rajagopal"],"url":"https:\/\/examples.javacodegeeks.com\/author\/rajagopal-parthasarathi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/53627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=53627"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/53627\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/13304"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=53627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=53627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=53627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}