| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| <title>Rolling file appenders :: Apache Log4j</title> |
| <link rel="canonical" href="https://logging.apache.org/log4j/2.x/manual/appenders/rolling-file.html"> |
| <meta name="generator" content="Antora 3.2.0-alpha.8"> |
| <link rel="stylesheet" href="../../_/css/site.css"> |
| <link rel="icon" href="../../_/../_images/favicon.ico" type="image/x-icon"> |
| <!-- `@asciidoctor/tabs` extension styles --> |
| <link rel="stylesheet" href="../../_/css/vendor/tabs.css"> |
| <style> |
| /* Swap colors of `IMPORTANT` and `WARNING` blocks */ |
| .doc .admonitionblock.important .icon { background-color: #f70; } |
| .doc .admonitionblock.warning .icon { background-color: #e40046; } |
| /* Default `h4`, `h5`, and `h6` are smaller than the normal text, fix header font sizing: */ |
| .doc h1 { font-size: 1.9rem; } |
| .doc h2 { font-size: 1.7rem; } |
| .doc h3 { font-size: 1.5rem; font-weight: 400; } |
| .doc h4 { font-size: 1.3rem; font-weight: 500; } |
| .doc h5 { font-size: 1.1rem; font-weight: 500; text-decoration: underline; } |
| .doc h6 { font-size: 0.9rem; font-weight: 500; text-decoration: underline; } |
| /* Default `code`, `pre`, and `.colist` (source code annotations) fonts are too big, adjust them: */ |
| .doc .colist>table code, .doc p code, .doc thead code { font-size: 0.8em; } |
| .doc pre { font-size: 0.7rem; } |
| .doc .colist { font-size: 0.75rem; } |
| /* Make links more visible: */ |
| .doc a { text-decoration: underline; } |
| .doc a code { text-decoration: underline; color: #1565c0; } |
| /* Tab header fonts aren't rendered good, adjusting the font weight: */ |
| .tablist > ul li { font-weight: 500; } |
| /* `page-toclevels` greater than 4 are not supported by Antora UI, patching it: */ |
| .toc .toc-menu li[data-level="4"] a { |
| padding-left: 2.75rem; |
| } |
| /* Replace the default highlight.js color for strings from red (unnecessarily signaling something negative) to green: */ |
| .hljs-string { |
| color: #0f8532; |
| } |
| </style> |
| </head> |
| <body class="article"> |
| <header class="header"> |
| <nav class="navbar"> |
| <div class="navbar-brand"> |
| <div class="navbar-item"> |
| <img src="../../_/../_images/logo-small-white.png" alt="Apache Log4j"/> |
| </div> |
| </div> |
| <div id="topbar-nav" class="navbar-menu"> |
| <div class="navbar-end"> |
| <a class="navbar-item" href="https://logging.apache.org">a subproject of <strong>Apache Logging Services</strong></a> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <div class="body"> |
| <div class="nav-container" data-component="ROOT" data-version=""> |
| <aside class="nav"> |
| <div class="panels"> |
| <div class="nav-panel-menu is-active" data-panel="menu"> |
| <nav class="nav-menu"> |
| <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button> |
| <h3 class="title"><a href="../../index.html">Home</a></h3> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="0"> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../../download.html">Download</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../../release-notes.html">Release notes</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="https://logging.apache.org/support.html">Support</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="https://logging.apache.org/security.html">Security</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="0"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../index.html">Manual</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../getting-started.html">Getting started</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../installation.html">Installation</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../api.html">API</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../api.html#loggers">Loggers</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../eventlogging.html">Event Logger</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../simple-logger.html">Simple Logger</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../status-logger.html">Status Logger</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../logbuilder.html">Fluent API</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../api.html#fish-tagging">Fish tagging</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../customloglevels.html">Levels</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../markers.html">Markers</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../thread-context.html">Thread Context</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../messages.html">Messages</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../flowtracing.html">Flow Tracing</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../implementation.html">Implementation</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../architecture.html">Architecture</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../config-intro.html">Configuration</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../configuration.html">Configuration file</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../systemproperties.html">Configuration properties</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../customconfig.html">Programmatic configuration</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../appenders.html">Appenders</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="file.html">File appenders</a> |
| </li> |
| <li class="nav-item is-current-page" data-depth="4"> |
| <a class="nav-link" href="rolling-file.html">Rolling file appenders</a> |
| </li> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="database.html">Database appenders</a> |
| </li> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="network.html">Network Appenders</a> |
| </li> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="message-queue.html">Message queue appenders</a> |
| </li> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="delegating.html">Delegating Appenders</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../layouts.html">Layouts</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="../json-template-layout.html">JSON Template Layout</a> |
| </li> |
| <li class="nav-item" data-depth="4"> |
| <a class="nav-link" href="../pattern-layout.html">Pattern Layout</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../lookups.html">Lookups</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../filters.html">Filters</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../scripts.html">Scripts</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../jmx.html">JMX</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../extending.html">Extending</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../plugins.html">Plugins</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../performance.html">Performance</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../async.html">Asynchronous loggers</a> |
| </li> |
| <li class="nav-item" data-depth="3"> |
| <a class="nav-link" href="../garbagefree.html">Garbage-free logging</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="0"> |
| <button class="nav-item-toggle"></button> |
| <span class="nav-text">References</span> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../plugin-reference.html">Plugin reference</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../javadoc.html">Java API reference</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="0"> |
| <button class="nav-item-toggle"></button> |
| <span class="nav-text">Resources</span> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../faq.html">F.A.Q.</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../migrate-from-log4j1.html">Migrating from Log4j 1</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../migrate-from-logback.html">Migrating from Logback</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../migrate-from-slf4j.html">Migrating from SLF4J</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../graalvm.html">Building GraalVM native images</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../hibernate.html">Integrating with Hibernate</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../jakarta.html">Integrating with Jakarta EE</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../soa.html">Integrating with service-oriented architectures</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../development.html">Development</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="0"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../../components.html">Components</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../log4j-iostreams.html">Log4j IOStreams</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../log4j-spring-boot.html">Log4j Spring Boot Support</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../log4j-spring-cloud-config-client.html">Log4j Spring Cloud Configuration</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../log4j-jul.html">JUL-to-Log4j bridge</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="../../log4j-to-jul.html">Log4j-to-JUL bridge</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="0"> |
| <button class="nav-item-toggle"></button> |
| <span class="nav-text">Related projects</span> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/jakarta/index.html">Log4j Jakarta EE</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/jmx-gui/index.html">Log4j JMX GUI</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/kotlin/index.html">Log4j Kotlin</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/scala/index.html">Log4j Scala</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/tools/index.html">Log4j Tools</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="https://logging.apache.org/log4j/transform/index.html">Log4j Transformation Tools</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </nav> |
| </div> |
| </div> |
| </aside> |
| </div> |
| <main class="article"> |
| <div class="toolbar" role="navigation"> |
| <button class="nav-toggle"></button> |
| <a href="../../index.html" class="home-link"></a> |
| <nav class="breadcrumbs" aria-label="breadcrumbs"> |
| <ul> |
| <li><a href="../../index.html">Home</a></li> |
| <li><a href="../index.html">Manual</a></li> |
| <li><a href="../implementation.html">Implementation</a></li> |
| <li><a href="../config-intro.html">Configuration</a></li> |
| <li><a href="../appenders.html">Appenders</a></li> |
| <li><a href="rolling-file.html">Rolling file appenders</a></li> |
| </ul> |
| </nav> |
| <div class="edit-this-page"><a href="https://github.com/apache/logging-log4j2/edit/2.x/src/site/antora/modules/ROOT/pages/manual/appenders/rolling-file.adoc">Edit this Page</a></div> |
| </div> |
| <div class="content"> |
| <aside class="toc sidebar" data-title="Contents" data-levels="4"> |
| <div class="toc-menu"></div> |
| </aside> |
| <article class="doc"> |
| <h1 class="page">Rolling file appenders</h1> |
| <div id="preamble"> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Log4j Core provides multiple appenders that allow to archive the current log file and truncate it.</p> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The rolling file appenders support many configuration options.</p> |
| </div> |
| <div class="paragraph"> |
| <p>If you are just interested in some configuration examples, see the <a href="#recipes">Configuration recipes</a> section.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="appenders"><a class="anchor" href="#appenders"></a>Appenders</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Log4j Core provides two rolling file appenders:</p> |
| </div> |
| <div class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>RollingFile</code></dt> |
| <dd> |
| <p>The <code>RollingFile</code> Appender uses |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/io/FileOutputStream.html"><code>FileOutputStream</code></a> |
| to access log files.</p> |
| </dd> |
| <dt class="hdlist1"><code>RollingRandomAccessFile</code></dt> |
| <dd> |
| <p>The <code>RollingRandomAccessFile</code> Appender uses |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/io/RandomAccessFile.html"><code>RandomAccessFile</code></a> |
| to access log files.</p> |
| </dd> |
| </dl> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Two appenders, even from different logger contexts, share a common |
| <a href="../architecture.html#AbstractManager" class="xref page"><code>RollingFileManager</code></a> if:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>they have the same non-null value of the <a href="#attr-fileName"><code>fileName</code> attribute</a>.</p> |
| </li> |
| <li> |
| <p>they have no <code>fileName</code> attribute, but have the same value of the <a href="#attr-filePattern"><code>filePattern</code> attribute</a>.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>Sharing a <code>RollingFileManager</code> guarantees that rollovers will occur only once, but requires most of the remaining configuration parameters to be the same.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="common-configuration"><a class="anchor" href="#common-configuration"></a>Common configuration</h3> |
| <table id="attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 1. Common configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <th class="tableblock halign-left valign-top" colspan="4"><p class="tableblock">Required</p></th> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-filePattern"></a>filePattern</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html"><code>Path</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The pattern for the archived log files. |
| See <a href="#conversion-patterns">Conversion patterns</a> for details</p> |
| <p class="tableblock">If <a href="#attr-fileName"><code>fileName</code></a> is <code>null</code>, the file pattern will also be used for the current file.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-name"></a>name</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The name of the appender.</p></td> |
| </tr> |
| <tr> |
| <th class="tableblock halign-left valign-top" colspan="4"><p class="tableblock">Optional</p></th> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-bufferSize"></a>bufferSize</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../systemproperties.html#log4j2.encoderByteBufferSize" class="xref page"><code>8192</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>The size of the |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html"><code>ByteBuffer</code></a> |
| internally used by the appender.</p> |
| </div> |
| <div class="paragraph"> |
| <p>See <a href="../appenders.html#buffering" class="xref page">Buffering</a> for more details.</p> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-bufferedIo"></a>bufferedIo</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If set to <code>true</code>, Log4j Core will format each log event in an internal buffer, before sending it to the underlying resource.</p> |
| <p class="tableblock">The <code>RandomAccessRollingFile</code> Appender always enables the internal buffer.</p> |
| <p class="tableblock">See <a href="../appenders.html#buffering" class="xref page">Buffering</a> for more details.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-createOnDemand"></a>createOnDemand</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The appender creates the file on-demand. The |
| appender only creates the file when a log event passes all filters and |
| is routed to this appender. Defaults to false.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-fileName"></a>fileName</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html"><code>Path</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>The path to the current log file, can be <code>null</code>. |
| If the folder containing the file does not exist, it will be created.</p> |
| </div> |
| <div class="admonitionblock warning"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-warning" title="Warning"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>This attribute should not contain any |
| <a href="../configuration.html#lazy-property-substitution" class="xref page">runtime lookups</a> |
| nor pattern converters.</p> |
| </div> |
| <div class="paragraph"> |
| <p>To use pattern converters, see <a href="#attr-filePattern"><code>filePattern</code></a>.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-filePermissions"></a>filePermissions</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermissions.html"><code>PosixFilePermissions</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>If not <code>null</code>, it specifies the POSIX file permissions to apply to each created file. |
| The permissions must be provided in the format used by |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermissions.html#fromString-java.lang.String-"><code>PosixFilePermissions.fromString()</code></a>, |
| e.g. <code>rw-rw----</code>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The underlying files system shall support |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFileAttributeView.html">POSIX</a> |
| file attribute view.</p> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-fileOwner"></a>fileOwner</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If not <code>null</code>, it specifies the file owner to apply to each created file.</p> |
| <p class="tableblock">The underlying files system shall support file |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/FileOwnerAttributeView.html">owner</a> |
| attribute view.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-fileGroup"></a>fileGroup</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If not <code>null</code>, it specifies the file group owner to apply to each created file.</p> |
| <p class="tableblock">The underlying files system shall support |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFileAttributeView.html">POSIX</a> |
| file attribute view.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-ignoreExceptions"></a>ignoreExceptions</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>false</code>, logging exception will be forwarded to the caller of the logging statement. |
| Otherwise, they will be ignored.</p> |
| <p class="tableblock">Logging exceptions are always also logged to <a href="../status-logger.html" class="xref page">Status Logger</a></p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="attr-immediateFlush"></a>immediateFlush</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If set to <code>true</code>, the appender will flush its internal buffer after each event.</p> |
| <p class="tableblock">See <a href="../appenders.html#buffering" class="xref page">Buffering</a> for more details.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table id="elements" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 2. Common nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="element-Filter"></a><a href="../filters.html" class="xref page"><code>Filter</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or one</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Allows filtering log events just before they are formatted and sent.</p> |
| <p class="tableblock">See also <a href="../filters.html#appender-stage" class="xref page">appender filtering stage</a>.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="element-Layout"></a><a href="../layouts.html" class="xref page"><code>Layout</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or one</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Formats log events.</p> |
| <p class="tableblock">See <a href="../layouts.html" class="xref page">Layouts</a> for more information.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="element-TriggeringPolicy"></a><a href="#TriggeringPolicy"><code>TriggeringPolicy</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><strong>one</strong></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Determines when to archive the current log file.</p> |
| <p class="tableblock">See <a href="#TriggeringPolicy">Triggering Policies</a> for more information.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="element-RolloverStrategy"></a><a href="#RolloverStrategy"><code>RolloverStrategy</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or one</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Determines the actions performed during a rollover.</p> |
| <p class="tableblock">See <a href="#RolloverStrategy">Rollover strategies</a> for more information.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="conversion-patterns"><a class="anchor" href="#conversion-patterns"></a>Conversion patterns</h3> |
| <div class="paragraph"> |
| <p>The <code>filePattern</code> attribute accepts the following pattern specifiers:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p><a href="../configuration.html#lazy-property-substitution" class="xref page">runtime lookups</a>, which are evaluated in |
| <a href="../lookups.html#global-context" class="xref page">a global context</a>.</p> |
| </li> |
| <li> |
| <p>a <code>%d{...}</code> pattern, functionally identical to the |
| <a href="../pattern-layout.html#converter-date" class="xref page">homonymous <code>PatternLayout</code> pattern</a> |
| except it uses the actual or inferred timestamp of the <strong>previous</strong> rollover.</p> |
| </li> |
| <li> |
| <p>a <code>%i</code> pattern that expands to the computed index for the archived file.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>All patterns accept also format specifiers, e.g. <code>%03i</code> prints the index as zero-padded number with 3 digits.</p> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The <code>$${date:...}</code> runtime lookup and <code>%d{...}</code> conversion pattern are not equivalent:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p><code>$${date:...}</code> formats the <strong>current</strong> date.</p> |
| </li> |
| <li> |
| <p><code>%d{...}</code> formats the date of the <strong>previous</strong> rollover.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>Setting the <code>filePattern</code> property to</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-none hljs">$${date:yyyy-MM}/%d{yyyy-MM-dd}.log</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>will write the <code>2024-06-30.log</code> log file into the <code>2024-07</code> directory. |
| Consider using</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-none hljs">%d{yyyy-MM}/%d{yyyy-MM-dd}.log</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>instead.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="RollingFileAppender"><a class="anchor" href="#RollingFileAppender"></a><code>RollingFile</code> configuration</h3> |
| <div class="paragraph"> |
| <p>The <code>RollingFile</code> Appender provides the following configuration options, beyond the <a href="#common-configuration">common ones</a>:</p> |
| </div> |
| <table id="RollingFileAppender-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 3. <code>RollingFile</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RollingFileAppender-attr-append"></a>append</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code>, the log file will be opened in |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardOpenOption.html#APPEND"><code>APPEND</code> mode</a>.</p> |
| <p class="tableblock">On most systems this guarantees atomic writes to the end of the file, even if the file is opened by multiple applications.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RollingFileAppender-attr-locking"></a>locking</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code>, Log4j will lock the log file at <strong>each</strong> log event.</p> |
| <p class="tableblock">Note that the effects of this setting depend on the Operating System: some systems like most POSIX OSes do not offer mandatory locking, but only advisory file locking.</p> |
| <p class="tableblock">This setting can also reduce the performance of the appender.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-RollingFileAppender" class="xref page">📖 Plugin reference for <code>RollingFile</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="RollingRandomAccessFileAppender"><a class="anchor" href="#RollingRandomAccessFileAppender"></a><code>RollingRandomAccessFile</code> configuration</h3> |
| <div class="paragraph"> |
| <p>The <code>RollingRandomAccessFile</code> Appender provides the following configuration options, beyond the <a href="#common-configuration">common ones</a>:</p> |
| </div> |
| <table id="RollingRandomAccessFileAppender-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 4. <code>RollingRandomAccessFile</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RollingRandomAccessFile-attr-append"></a>append</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code>, the appender starts writing at the end of the file.</p> |
| <p class="tableblock">This setting does not give the same atomicity guarantees as for the |
| <a href="#RollingFileAppender-attr-append"><code>RollingFile</code> Appender</a>. |
| The log file cannot be opened by multiple applications at the same time.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-RollingRandomAccessFileAppender" class="xref page">📖 Plugin reference for <code>RollingRandomAccessFile</code></a></p> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="TriggeringPolicy"><a class="anchor" href="#TriggeringPolicy"></a>Triggering Policies</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Triggering policies are Log4j plugins that implement the |
| <a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/TriggeringPolicy.html"><code>TriggeringPolicy</code></a> |
| interface and are used to decide when is it time to rollover the current log file.</p> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-TriggeringPolicy" class="xref page">📖 Plugin reference for <code>TriggeringPolicy</code></a></p> |
| </div> |
| <div class="sect2"> |
| <h3 id="TriggeringPolicy-common"><a class="anchor" href="#TriggeringPolicy-common"></a>Common concerns</h3> |
| <div class="paragraph"> |
| <p>Triggering policies usually decide to rollover a file based on two parameters:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>the size of the current file.</p> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>While all JVMs can reliably check the size of a file, Log4j only checks it at startup and at each rollover and infers all file size changes, based on the size of logs delivered. |
| If multiple managers are writing to the same file, the size computation will be off.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </li> |
| <li> |
| <p>the creation timestamp of the current file.</p> |
| <div class="admonitionblock important"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-important" title="Important"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Not all file systems support a creation timestamp. |
| Most notably, POSIX does not specify such a timestamp, so the value used by Log4j might depend on the type of filesystem used and the JVM. |
| If the creation timestamp is not available, the last modification timestamp is used, which might differ by up to a whole rollover period.</p> |
| </div> |
| <div class="paragraph"> |
| <p>See |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/BasicFileAttributes.html#creationTime--"><code>BasicFileAttributes.creationTime()</code></a> |
| for more details.</p> |
| </div> |
| <div class="paragraph"> |
| <p>After the first rollover Log4j uses the timestamp of the rollover as creation timestamp.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="OnStartupTriggeringPolicy"><a class="anchor" href="#OnStartupTriggeringPolicy"></a><code>OnStartupTriggeringPolicy</code></h3> |
| <div class="paragraph"> |
| <p>The <code>OnStartupTriggeringPolicy</code> policy causes a rollover only once during the lifetime of a JVM. |
| A rollover will occur if the log file was created before the start time of the current JVM and the minimum file size is met or exceeded.</p> |
| </div> |
| <table id="OnStartupTriggeringPolicy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 5. <code>OnStartupTriggeringPolicy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="OnStartupTriggeringPolicy-attr-minSize"></a>minSize</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>long</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>1</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The minimum size the file must have to roll over.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The <code>OnStartupTriggeringPolicy</code> uses JMX to retrieve the start time of the JVM.</p> |
| </div> |
| <div class="paragraph"> |
| <p>On platforms where JMX is absent or disabled, like Android or |
| <a href="https://cloud.google.com/appengine">Google App Engine</a>, the <code>OnStartupTriggeringPolicy</code> will use the timestamp, when its class was loaded instead.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-OnStartupTriggeringPolicy" class="xref page">📖 Plugin reference for <code>OnStartupTriggeringPolicy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="CronTriggeringPolicy"><a class="anchor" href="#CronTriggeringPolicy"></a><code>CronTriggeringPolicy</code></h3> |
| <div class="paragraph"> |
| <p>The <code>CronTriggeringPolicy</code> triggers rollover based on a CRON expression.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The |
| <a href="#attr-filePattern"><code>filePattern</code></a> |
| attribute of the Appender should contain a |
| <a href="#conversion-pattern-date"><code>%d{...}</code> timestamp</a>, otherwise the target file will be overwritten on each rollover.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="admonitionblock warning"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-warning" title="Warning"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>This policy is controlled by a timer and is asynchronous in processing log events, so it is possible that log events from the previous or next period may appear at the beginning or end of the log file.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <table id="CronTriggeringPolicy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 6. <code>CronTriggeringPolicy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 11.1111%;"> |
| <col style="width: 11.1111%;"> |
| <col style="width: 22.2222%;"> |
| <col style="width: 55.5556%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="CronTriggeringPolicy-attr-evaluateOnStartup"></a>evaluateOnStartup</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">On startup the cron expression will be evaluated against the current file’s creation timestamp. |
| If a rollover should have occurred between that time and the current time the file will be immediately rolled over.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="CronTriggeringPolicy-attr-schedule"></a>schedule</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/util/CronExpression.html"><code>CronExpression</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>0 0 0 * * ?</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>The cron expression, using the same syntax as the |
| <a href="https://www.quartz-scheduler.org/">Quartz scheduler</a>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The supported fields are in order:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>second</p> |
| </li> |
| <li> |
| <p>minute</p> |
| </li> |
| <li> |
| <p>hour</p> |
| </li> |
| <li> |
| <p>day of month</p> |
| </li> |
| <li> |
| <p>month</p> |
| </li> |
| <li> |
| <p>day of week</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>See |
| <a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/util/CronExpression.html"><code>CronExpression</code></a> |
| for a full specification of the format.</p> |
| </div></div></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-CronTriggeringPolicy" class="xref page">📖 Plugin reference for <code>CronTriggeringPolicy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="SizeBasedTriggeringPolicy"><a class="anchor" href="#SizeBasedTriggeringPolicy"></a><code>SizeBasedTriggeringPolicy</code></h3> |
| <div class="paragraph"> |
| <p>The <code>SizeBasedTriggeringPolicy</code> causes a rollover once the file has reached the specified size.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The size can be specified in bytes, with the suffix KB, MB, GB, or TB for example <code>20MB</code>. |
| size. |
| The size may also contain a fractional value such as <code>1.5 MB</code>. |
| The size is evaluated using the Java root Locale so a period must always be used for the fractional unit.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>When combined with a time-based triggering policy, the |
| <a href="#attr-filePattern"><code>filePattern</code></a> |
| attribute of the Appender should contain an |
| <a href="#conversion-pattern-integer"><code>%i</code> conversion pattern</a>. |
| Otherwise, the target file will be overwritten on each rollover.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <table id="SizeBasedTriggeringPolicy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 7. <code>SizeBasedTriggeringPolicy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="SizeBasedTriggeringPolicy-attr-size"></a>size</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/FileSize.html"><code>FileSize</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>10 MB</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>The maximum file size of the current log file. |
| Once this size is reached, a rollover will occur.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The syntax of this attribute is:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre><number> [ " " ] [ <unit> ]</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>i.e.:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>a number recognized by |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/text/NumberFormat.html#getInstance--"><code>NumberFormat</code></a></p> |
| </li> |
| <li> |
| <p>followed by optional whitespace</p> |
| </li> |
| <li> |
| <p>followed by an optional unit: <code>k</code>, <code>kB</code>, <code>M</code>, <code>MB</code>, <code>G</code>, <code>GB</code>, <code>T</code>, <code>TB</code>.</p> |
| </li> |
| </ul> |
| </div></div></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-SizeBasedTriggeringPolicy" class="xref page">📖 Plugin reference for <code>SizeBasedTriggeringPolicy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="TimeBasedTriggeringPolicy"><a class="anchor" href="#TimeBasedTriggeringPolicy"></a><code>TimeBasedTriggeringPolicy</code></h3> |
| <div class="paragraph"> |
| <p>The <code>TimeBasedTriggeringPolicy</code> causes a rollover, when the smallest time unit in <code>filePattern</code> changes value. |
| So the rollover can occur at the end of a month, week, at midnight, end of the hour, etc.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The |
| <a href="#attr-filePattern"><code>filePattern</code></a> |
| attribute of the Appender should contain a |
| <a href="#conversion-pattern-date"><code>%d{...}</code> timestamp</a>, otherwise the target file will be overwritten on each rollover.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Multiple <code>%d</code> patterns can be used. |
| The rollover frequency time unit will be determined by the last <code>%d</code> pattern.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <table id="TimeBasedTriggeringPolicy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 8. <code>TimeBasedTriggeringPolicy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="TimeBasedTriggeringPolicy-attr-interval"></a>interval</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>1</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">How often a rollover should occur based on the most |
| specific time unit in the last <code>%d{...}</code> pattern.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="TimeBasedTriggeringPolicy-attr-modulate"></a>modulate</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>If <code>true</code>, the rollover will be aligned to a boundary of <code>interval</code> time units.</p> |
| </div> |
| <div class="paragraph"> |
| <p>For example, if the rotation frequency is hourly with an interval of <code>4</code> and the application starts at <code>3:14</code>:</p> |
| </div> |
| <div class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>false</code></dt> |
| <dd> |
| <p>Will roll over at <code>3:00</code>, <code>7:00</code>, <code>11:00</code>, <code>15:00</code>, <code>19:00</code> and <code>23:00</code> each day.</p> |
| </dd> |
| <dt class="hdlist1"><code>true</code></dt> |
| <dd> |
| <p>Will roll over at <code>0:00</code>, <code>4:00</code>, <code>8:00</code>, <code>12:00</code>, <code>16:00</code> and <code>20:00</code> each day.</p> |
| </dd> |
| </dl> |
| </div> |
| <div class="paragraph"> |
| <p>Only applies if <a href="#TimeBasedTriggeringPolicy-attr-interval"><code>interval</code></a> is greater than <code>1</code>.</p> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="TimeBasedTriggeringPolicy-attr-maxRandomDelay"></a>maxRandomDelay</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>0</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Indicates the maximum number of seconds to randomly delay a rollover.</p> |
| <p class="tableblock">This setting is useful on servers where multiple applications are configured to roll over log files at the same time and can spread the load of doing so across time.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>When the rollover frequency is daily or lower, the rolling file appender will rotate files at midnight of the server’s default timezone.</p> |
| </div> |
| <div class="paragraph"> |
| <p>You can modify the time of the rollover by specifying a different timezone in the <code>%d</code> pattern. |
| See <a href="../pattern-layout.html#converter-date" class="xref page"><code>date</code> converter syntax</a> for more details.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-TimeBasedTriggeringPolicy" class="xref page">📖 Plugin reference for <code>TimeBasedTriggeringPolicy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="Policies"><a class="anchor" href="#Policies"></a>Multiple policies</h3> |
| <div class="paragraph"> |
| <p>A rolling file appender allows only <strong>one</strong> <a href="#element-TriggeringPolicy">nested triggering policy element</a>. |
| If you wish to use multiple policies, you need to wrap them in a <code>Policies</code> element. |
| The element itself has no configuration attributes.</p> |
| </div> |
| <div class="admonitionblock warning"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-warning" title="Warning"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The effects of using <strong>both</strong> time-based triggering policies (<a href="#CronTriggeringPolicy"><code>CronTriggeringPolicy</code></a> and <a href="#TimeBasedTriggeringPolicy"><code>TimeBasedTriggeringPolicy</code></a>) at the same time are undefined.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>For example, the following XML fragment defines policies that rollover the log:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>when the JVM starts.</p> |
| </li> |
| <li> |
| <p>when the log size reaches 10 MB.</p> |
| </li> |
| <li> |
| <p>at midnight local time.</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_1" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_1_xml" class="tab"> |
| <p>XML</p> |
| </li> |
| <li id="_tabs_1_json" class="tab"> |
| <p>JSON</p> |
| </li> |
| <li id="_tabs_1_yaml" class="tab"> |
| <p>YAML</p> |
| </li> |
| <li id="_tabs_1_properties" class="tab"> |
| <p>Properties</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_1_xml--panel" class="tabpanel" aria-labelledby="_tabs_1_xml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/policies.xml"><code>log4j2.xml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><RollingFile name="FILE" |
| fileName="app.log" |
| filePattern="app.%d{yyyy-MM-dd}.%i.log"> |
| <JsonTemplateLayout/> |
| <Policies> |
| <OnStartupTriggeringPolicy/> |
| <SizeBasedTriggeringPolicy/> |
| <TimeBasedTriggeringPolicy/> |
| </Policies> |
| </RollingFile></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_1_json--panel" class="tabpanel" aria-labelledby="_tabs_1_json"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/policies.json"><code>log4j2.json</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"RollingFile": { |
| "name": "FILE", |
| "fileName": "app.log", |
| "filePattern": "app.%d{yyyy-MM-dd}.%i.log", |
| "JsonTemplateLayout": {}, |
| "Policies": { |
| "OnStartupTriggeringPolicy": {}, |
| "SizeBasedTriggeringPolicy": {}, |
| "TimeBasedTriggeringPolicy": {} |
| } |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_1_yaml--panel" class="tabpanel" aria-labelledby="_tabs_1_yaml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/policies.yaml"><code>log4j2.yaml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">RollingFile: |
| name: "FILE" |
| fileName: "app.log" |
| filePattern: "app.%d{yyyy-MM-dd}.%i.log" |
| JsonTemplateLayout: {} |
| Policies: |
| OnStartupTriggeringPolicy: {} |
| SizeBasedTriggeringPolicy: {} |
| TimeBasedTriggeringPolicy: {}</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_1_properties--panel" class="tabpanel" aria-labelledby="_tabs_1_properties"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/policies.properties"><code>log4j2.properties</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-properties hljs" data-lang="properties">appender.0.type = RollingFile |
| appender.0.name = FILE |
| appender.0.fileName = app.log |
| appender.0.filePattern = app.%d{yyyy-MM-dd}.%i.log |
| |
| appender.0.layout.type = JsonTemplateLayout |
| |
| appender.0.policy.type = Policies |
| appender.0.policy.0.type = OnStartupTriggeringPolicy |
| appender.0.policy.1.type = SizeBasedTriggeringPolicy |
| appender.0.policy.2.type = TimeBasedTriggeringPolicy</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-CompositeTriggeringPolicy" class="xref page">📖 Plugin reference for <code>Policies</code></a></p> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="RolloverStrategy"><a class="anchor" href="#RolloverStrategy"></a>Rollover strategies</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>A rollover strategy determines how old archive files are rotated or deleted to make place for newer ones. |
| The actions performed during a rollover include:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>Renaming files in a cyclic way. |
| See <a href="#RolloverStrategy-index">Incrementing file indexes</a> for more details.</p> |
| </li> |
| <li> |
| <p>Compression of archived log files. |
| See <a href="#RolloverStrategy-compress">Compressing archived files</a> for more details.</p> |
| </li> |
| <li> |
| <p>Deletion of old archived log files. |
| See <a href="#DeleteAction"><code>Delete</code> action</a> for more details.</p> |
| </li> |
| <li> |
| <p>Changing the POSIX permissions of archived log files. |
| See <a href="#PosixViewAttributeAction"><code>PosixViewAttribute</code> action</a> for more details.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p>There are two different rollover strategies available out of the box:</p> |
| </div> |
| <div class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>DefaultRolloverStrategy</code></dt> |
| <dd> |
| <p>This is the default strategy used if the |
| <a href="#attr-fileName"><code>fileName</code> configuration attribute</a> |
| is specified. |
| It stores the current log file in the location specified by <code>fileName</code> and the archived log files in the location specified by |
| <a href="#attr-filePattern"><code>filePattern</code></a>.</p> |
| </dd> |
| <dt class="hdlist1"><code>DirectWriteRolloverStrategy</code></dt> |
| <dd> |
| <p>This is the default strategy used if the |
| <a href="#attr-fileName"><code>fileName</code> configuration attribute</a> |
| is <code>null</code>. |
| It stores the current log file directly in its rolled over location specified by <a href="#attr-filePattern"><code>filePattern</code></a>.</p> |
| </dd> |
| </dl> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Using runtime lookups in the <code>fileName</code> configuration attribute is discouraged, since it will break the logic of the <code>DefaultRolloverStrategy</code>. |
| Use the <code>DirectWriteRolloverStrategy</code> instead by omitting the <code>fileName</code> attribute in your configuration.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="RolloverStrategy-configuration"><a class="anchor" href="#RolloverStrategy-configuration"></a>Common configuration</h3> |
| <div class="paragraph"> |
| <p>Both rollover strategies support the following configuration parameters:</p> |
| </div> |
| <table id="RolloverStrategy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 9. Common rollover strategy configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RolloverStrategy-attr-compressionLevel"></a>compressionLevel</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>7</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Determine the compression level of archived log files.</p> |
| <p class="tableblock">See <a href="#RolloverStrategy-compress">Compressing archived files</a> for more details.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RolloverStrategy-attr-tempCompressedFilePattern"></a>tempCompressedFilePattern</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html"><code>Path</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Temporary location to store compressed files.</p> |
| <p class="tableblock">See <a href="#RolloverStrategy-compress">Compressing archived files</a> for more details.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="RolloverStrategy-attr-stopCustomActionsOnError"></a>stopCustomActionsOnError</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code>, <a href="#AbstractPathAction">custom actions</a> will be stopped if one of them fails.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table id="RolloverStrategy-elements" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 10. Common Rollover Strategy nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="element-Action"></a><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/Action.html"><code>Action</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Additional actions to perform on a rollover beyond file rotation and compression.</p> |
| <p class="tableblock">See <a href="#AbstractPathAction">Optional actions</a> for more details.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="DefaultRolloverStrategy"><a class="anchor" href="#DefaultRolloverStrategy"></a><code>DefaultRolloverStrategy</code> configuration</h3> |
| <div class="paragraph"> |
| <p>The <code>DefaultRolloverStrategy</code> supports additional attributes that control the <a href="#RolloverStrategy-index">incrementation of file indexes</a>.</p> |
| </div> |
| <table id="DefaultRolloverStrategy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 11. <code>DefaultRolloverStrategy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DefaultRolloverStrategy-attr-fileIndex"></a>fileIndex</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><em>enumeration</em></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>max</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>Determines the strategy for determining the value of the <a href="#conversion-pattern-integer"><code>%i</code></a> conversion pattern for the current log file.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The supported values are:</p> |
| </div> |
| <div class="dlist"> |
| <dl> |
| <dt class="hdlist1"><a href="#RolloverStrategy-index-min"><code>min</code></a></dt> |
| <dd> |
| <p>uses the value of the <a href="#DefaultRolloverStrategy-attr-min"><code>min</code></a> attribute.</p> |
| </dd> |
| <dt class="hdlist1"><a href="#RolloverStrategy-index-max"><code>max</code></a></dt> |
| <dd> |
| <p>uses the first unused integer between the <a href="#DefaultRolloverStrategy-attr-min"><code>min</code></a> and <a href="#DefaultRolloverStrategy-attr-max"><code>max</code></a> attributes.</p> |
| </dd> |
| <dt class="hdlist1"><a href="#RolloverStrategy-index-nomax"><code>nomax</code></a></dt> |
| <dd> |
| <p>uses the first unused integer not lower than the value of the <a href="#DefaultRolloverStrategy-attr-min"><code>min</code></a> attribute.</p> |
| </dd> |
| </dl> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DefaultRolloverStrategy-attr-min"></a>min</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>1</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Minimum value for the <a href="#conversion-pattern-integer"><code>%i</code></a> conversion pattern.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DefaultRolloverStrategy-attr-max"></a>max</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>7</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Maximum value for the <a href="#conversion-pattern-integer"><code>%i</code></a> conversion pattern.</p> |
| <p class="tableblock">This attribute is <strong>ignored</strong> if <a href="#DefaultRolloverStrategy-attr-fileIndex"><code>fileIndex</code></a> is set to <code>nomax</code>.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-DefaultRolloverStrategy" class="xref page">📖 Plugin reference for <code>DefaultRolloverStrategy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="DirectWriteRolloverStrategy"><a class="anchor" href="#DirectWriteRolloverStrategy"></a><code>DirectWriteRolloverStrategy</code> configuration</h3> |
| <div class="paragraph"> |
| <p>The <code>DirectWriteRolloverStrategy</code> has a reduced set of configuration options for <a href="#RolloverStrategy-index">incrementing the file index</a>:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>the minimum file index is always <code>1</code>.</p> |
| </li> |
| <li> |
| <p>the incrementing strategy is always <a href="#RolloverStrategy-index-max"><code>max</code></a>.</p> |
| </li> |
| <li> |
| <p>the maximum file index can be configured using the following configuration attribute:</p> |
| <table id="DirectWriteRolloverStrategy-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 12. <code>DirectWriteRolloverStrategy</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DirectWriteRolloverStrategy-attr-maxFiles"></a>maxFiles</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>7</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Maximum value for the <code>%i</code> conversion pattern.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-DirectWriteRolloverStrategy" class="xref page">📖 Plugin reference for <code>DirectWriteRolloverStrategy</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="RolloverStrategy-index"><a class="anchor" href="#RolloverStrategy-index"></a>Incrementing file indexes</h3> |
| <div class="paragraph"> |
| <p>During a rollover event, the current log file is moved to the location determined by evaluating |
| <a href="#attr-filePattern"><code>filePattern</code></a>, using <a href="#DefaultRolloverStrategy-attr-min"><code>min</code></a> as value for the <a href="#conversion-pattern-integer"><code>%i</code> conversion pattern</a>. |
| If an old log file is already present in that location, the rolling file appender:</p> |
| </div> |
| <div class="olist arabic"> |
| <ol class="arabic"> |
| <li> |
| <p>Tries to increment the value of <code>%i</code> using the strategy specified by the <a href="#DefaultRolloverStrategy-attr-fileIndex"><code>fileIndex</code> configuration attribute</a>.</p> |
| </li> |
| <li> |
| <p>If that fails, it removes the oldest log file and rotates the remaining ones to make place for a new log archive.</p> |
| </li> |
| </ol> |
| </div> |
| <div class="paragraph"> |
| <p>There are three strategies available:</p> |
| </div> |
| <div id="RolloverStrategy-index-min" class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>min</code></dt> |
| <dd> |
| <p>Using the <code>min</code> strategy, the <strong>newest</strong> log file will have index <code>min</code> and the oldest one will have index <code>max</code>.</p> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>This is the log rotation strategy used by traditional UNIX tools and by Log4j 1. |
| It is <strong>not</strong> the default strategy of Log4j 2.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>Assuming <code>min="1"</code> and <code>max="3"</code> the rotation of the log files is represented in the graph below:</p> |
| </div> |
| <div class="imageblock kroki"> |
| <div class="content"> |
| <img src="../../_images/diag-d5122741a680d765fa3170a444015b615a1fdafd.svg" alt="Diagram"> |
| </div> |
| </div> |
| </dd> |
| </dl> |
| </div> |
| <div id="RolloverStrategy-index-max" class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>max</code></dt> |
| <dd> |
| <p>Using the <code>max</code> strategy, the <strong>oldest</strong> log file will have index <code>min</code> and the newest one will have index <code>max</code>.</p> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>This is the default strategy since Log4j 2.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>Assuming <code>min="1"</code> and <code>max="3"</code> the rotation of the log files is represented in the graph below:</p> |
| </div> |
| <div class="imageblock kroki"> |
| <div class="content"> |
| <img src="../../_images/diag-35cc4e8101ffe76d0edc44ed334a6273018dc51b.svg" alt="Diagram"> |
| </div> |
| </div> |
| </dd> |
| </dl> |
| </div> |
| <div id="RolloverStrategy-index-nomax" class="dlist"> |
| <dl> |
| <dt class="hdlist1"><code>nomax</code></dt> |
| <dd> |
| <div class="paragraph"> |
| <p>Using the <code>nomax</code> strategy no files will ever be deleted and newer archive files will be assigned increasing index numbers, starting from <code>min</code>.</p> |
| </div> |
| <div class="imageblock kroki"> |
| <div class="content"> |
| <img src="../../_images/diag-768e5e02508ea736d8901892b519a6d3a7a770ab.svg" alt="Diagram"> |
| </div> |
| </div> |
| </dd> |
| </dl> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="RolloverStrategy-compress"><a class="anchor" href="#RolloverStrategy-compress"></a>Compressing archived files</h3> |
| <div class="paragraph"> |
| <p>When the current log file is archived, the rolling file appender can compress it. |
| Compression is activated, based on the extension of the archived file name. |
| The following extensions are recognized:</p> |
| </div> |
| <table class="tableblock frame-all grid-all stretch"> |
| <colgroup> |
| <col style="width: 25%;"> |
| <col style="width: 25%;"> |
| <col style="width: 50%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Extension</th> |
| <th class="tableblock halign-left valign-top">Supports <code>compressionLevel</code></th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-zip"></a><code>.zip</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✓</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">ZIP archive using the |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/util/zip/DeflaterOutputStream.html">DEFLATE</a> |
| algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-gz"></a><code>.gz</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✓</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/util/zip/GZIPOutputStream.html">GZIP</a> archive using the DEFLATE algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-bz2"></a><code>.bz2</code><a href="#commons-compress-dep"><sup>dep</sup></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✗</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.html">BZip2</a> algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-deflate"></a><code>.deflate</code><a href="#commons-compress-dep"><sup>dep</sup></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✗</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStream.html">DEFLATE</a> algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-pack200"></a><code>.pack200</code><a href="#commons-compress-dep"><sup>dep</sup></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✗</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/compressors/pack200/package-summary.html">Pack200</a> algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-xz"></a><code>.xz</code> <a href="#commons-compress-dep"><sup>dep</sup></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✗</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/compressors/xz/package-summary.html">XZ</a> algorithm</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a id="RolloverStrategy-compress-zst"></a><code>.zst</code> <a href="#commons-compress-dep"><sup>dep</sup></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">✗</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/compressors/zstandard/package-summary.html">ZStandard</a> algorithm</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p>If the <a href="#RolloverStrategy-attr-tempCompressedFilePattern"><code>tempCompressedFilePattern</code></a> attribute is set, the current log file:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>will be compressed and stored in the location given by <code>tempCompressedFilePattern</code></p> |
| </li> |
| <li> |
| <p>and then it will be moved to the location given by <a href="#attr-filePattern"><code>filePattern</code></a>.</p> |
| </li> |
| </ul> |
| </div> |
| <div id="commons-compress-dep" class="dlist"> |
| <dl> |
| <dt class="hdlist1"><sup>dep</sup></dt> |
| <dd> |
| <p>Additional dependencies are required to use these compression algorithms:</p> |
| <div class="openblock"> |
| <div class="content"> |
| <div id="_tabs_2" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_2_maven" class="tab"> |
| <p>Maven</p> |
| </li> |
| <li id="_tabs_2_gradle" class="tab"> |
| <p>Gradle</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_2_maven--panel" class="tabpanel" aria-labelledby="_tabs_2_maven"> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><dependency> |
| <groupId>org.apache.commons</groupId> |
| <artifactId>commons-compress</artifactId> |
| <version>1.27.1</version> |
| <scope>runtime</scope> |
| </dependency></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_2_gradle--panel" class="tabpanel" aria-labelledby="_tabs_2_gradle"> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">runtimeOnly 'org.apache.commons:commons-compress:1.27.1'</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The <code>.xz</code> and <code>.zst</code> extensions require <strong>additional</strong> dependencies. |
| See |
| <a href="https://commons.apache.org/proper/commons-compress/index.html">Commons Compress documentation</a> |
| for more details.</p> |
| </div> |
| </dd> |
| </dl> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="AbstractPathAction"><a class="anchor" href="#AbstractPathAction"></a>Optional actions</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>The rotation of files and compression is <strong>always</strong> handled automatically by the rolling file appenders. |
| Since Log4j 2.6, additional actions can be configured manually.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Log4j Core provides out-of-the-box two actions:</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p>the <a href="#DeleteAction"><code>Delete</code> action</a> to delete old log files after a rollover,</p> |
| </li> |
| <li> |
| <p>the <a href="#PosixViewAttributeAction"><code>PosixViewAttribute</code> action</a> to change the POSIX permissions of old log files.</p> |
| </li> |
| </ul> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-AbstractPathAction" class="xref page">📖 Plugin reference for <code>AbstractPathAction</code></a></p> |
| </div> |
| <div class="sect2"> |
| <h3 id="AbstractPathAction-config"><a class="anchor" href="#AbstractPathAction-config"></a>Common action configuration</h3> |
| <div class="paragraph"> |
| <p>Both actions support the following configuration attributes:</p> |
| </div> |
| <table id="AbstractPathAction-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 13. Common action configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="AbstractPathAction-attr-basePath"></a>basePath</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html"><code>Path</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">It sets the base directory for the action. |
| The action will be limited to files in this directory, and all paths will be relative to this directory.</p> |
| <p class="tableblock"><strong>Required</strong></p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="AbstractPathAction-attr-followLinks"></a>followLinks</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>If set to <code>true</code>, the action will follow symbolic links.</p> |
| </div> |
| <div class="admonitionblock warning"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-warning" title="Warning"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Setting this value to <code>true</code> will allow the action to access files outside <a href="#AbstractPathAction-attr-basePath"><code>basePath</code></a>, which might introduce a security risk.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="AbstractPathAction-attr-maxDepth"></a>maxDepth</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>1</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The maximum number of directory levels to visit. |
| By default, the action does not recurse into subdirectories of <a href="#AbstractPathAction-attr-basePath"><code>basePath</code></a>.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table id="AbstractPathAction-elements" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 14. Common action nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="AbstractPathAction-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of path conditions. |
| The action will only be performed on files for which the condition returns <code>true</code>.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="DeleteAction"><a class="anchor" href="#DeleteAction"></a><code>Delete</code> action</h3> |
| <div class="paragraph"> |
| <p>The <code>Delete</code> Action deletes old log files that match the configured condition.</p> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>A limited version of this action is performed automatically to <a href="#RolloverStrategy-index">increment file indexes</a>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>You only need an explicit <code>Delete</code> Action if you use a <a href="#conversion-pattern-date"><code>%d</code> pattern</a>.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>Besides the <a href="#AbstractPathAction-config">common configuration options</a> the <code>Delete</code> Action also supports the following options:</p> |
| </div> |
| <table id="DeleteAction-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 15. <code>Delete</code> Action configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DeleteAction-attr-testMode"></a>testMode</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>boolean</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code>, no files will be deleted, but a <a href="../status-logger.html" class="xref page">Status Logger</a> message of level <code>INFO</code> will be issued instead.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table id="DeleteAction-elements" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 16. <code>Delete</code> Action nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DeleteAction-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If present, the action will only be performed on files for which the condition returns <code>true</code>.</p> |
| <p class="tableblock"><strong>Required</strong>, unless a <a href="#DeleteAction-element-ScriptCondition"><code>ScriptCondition</code></a> is provided, in which case these elements are ignored.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DeleteAction-element-PathSorter"></a><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/PathSorter.html"><code>PathSorter</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or one</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Provides a sorting order for files contained in <a href="#AbstractPathAction-attr-basePath"><code>basePath</code></a>.</p> |
| <p class="tableblock">The default implementation is |
| <a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.html"><code>PathSortByModificationTime</code></a>, |
| which sorts files by ascending modification timestamp.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="DeleteAction-element-ScriptCondition"></a><a href="#ScriptCondition"><code>ScriptCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or one</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If present, all the <a href="#DeleteAction-element-PathCondition">nested <code>PathCondition</code>s</a> are ignored and the provided script is executed to select the file to delete.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-DeleteAction" class="xref page">📖 Plugin reference for <code>Delete</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="PosixViewAttributeAction"><a class="anchor" href="#PosixViewAttributeAction"></a><code>PosixViewAttribute</code> action</h3> |
| <div class="paragraph"> |
| <p>This action allows modifying the POSIX attributes (owner, group and permissions) of archive log files.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>By default, the POSIX attributes are inherited from the current log file.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This action is only necessary if archived log files must have different attributes.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>Besides the <a href="#AbstractPathAction-config">common configuration options</a> the <code>PosixViewAttribute</code> Action also supports the following options.</p> |
| </div> |
| <table id="PosixViewAttributeAction-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 17. <code>PosixViewAttribute</code> Action configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="PosixViewAttributeAction-attr-filePermissions"></a>filePermissions</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermissions.html"><code>PosixFilePermissions</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph"> |
| <p>If not <code>null</code>, it specifies the POSIX file permissions to apply to each created file. |
| The permissions must be provided in the format used by |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermissions.html#fromString-java.lang.String-"><code>PosixFilePermissions.fromString()</code></a>, |
| e.g. <code>rw-rw----</code>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The underlying files system shall support |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFileAttributeView.html">POSIX</a> |
| file attribute view.</p> |
| </div></div></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="PosixViewAttributeAction-attr-fileOwner"></a>fileOwner</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If not <code>null</code>, it specifies the file owner to apply to each created file.</p> |
| <p class="tableblock">The underlying files system shall support file |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/FileOwnerAttributeView.html">owner</a> |
| attribute view.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="PosixViewAttributeAction-attr-fileGroup"></a>fileGroup</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If not <code>null</code>, it specifies the file group owner to apply to each created file.</p> |
| <p class="tableblock">The underlying files system shall support |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFileAttributeView.html">POSIX</a> |
| file attribute view.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table id="PosixViewAttributeAction-elements" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 18. <code>PosixViewAttribute</code> Action nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="PosixViewAttributeAction-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">one or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of conditions to select the files to modify.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-PosixViewAttributeAction" class="xref page">📖 Plugin reference for <code>PosixViewAttribute</code></a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="PathCondition"><a class="anchor" href="#PathCondition"></a>Path conditions</h3> |
| <div class="paragraph"> |
| <p>To select the files for additional actions, Log4j provides the following path conditions:</p> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfAccumulatedFileSize"><a class="anchor" href="#IfAccumulatedFileSize"></a><code>IfAccumulatedFileSize</code></h4> |
| <div class="paragraph"> |
| <p>When evaluated on a list of files, this condition sums the size of each file with the size of the preceding files. |
| It returns <code>true</code> for files that exceed a configurable threshold.</p> |
| </div> |
| <div class="admonitionblock important"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-important" title="Important"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The result of this condition depends on the sorting order on files. |
| See <a href="#DeleteAction-element-PathSorter"><code>PathSorter</code></a> for more information.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <table id="IfAccumulatedFileSize-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 19. <code>IfAccumulatedFileSize</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAccumulatedFileSize-attr-exceeds"></a>exceeds</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/FileSize.html"><code>FileSize</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The threshold size for the condition to match.</p> |
| <p class="tableblock">Admits the same syntax as the <a href="#SizeBasedTriggeringPolicy-attr-size"><code>size</code> attribute of <code>SizeBasedTriggeringPolicy</code></a>.</p> |
| <p class="tableblock"><strong>Required</strong></p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 20. <code>IfAccumulatedFileSize</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAccumulatedFileSize-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of optional nested conditions. |
| This condition matches only if <strong>all</strong> the nested conditions also match.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfAccumulatedFileSize" class="xref page">📖 Plugin reference for <code>IfAccumulatedFileSize</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfAccumulatedFileCount"><a class="anchor" href="#IfAccumulatedFileCount"></a><code>IfAccumulatedFileCount</code></h4> |
| <div class="paragraph"> |
| <p>When evaluated on a list of files, this condition returns <code>true</code> if the 1-based index of a file exceeds a configurable threshold.</p> |
| </div> |
| <div class="admonitionblock important"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-important" title="Important"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>The result of this condition depends on the sorting order on files. |
| See <a href="#DeleteAction-element-PathSorter"><code>PathSorter</code></a> for more information.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <table id="IfAccumulatedFileCount-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 21. <code>IfAccumulatedFileCount</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAccumulatedFileCount-attr-exceeds"></a>exceeds</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>int</code></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The threshold for the condition to match.</p> |
| <p class="tableblock"><strong>Required</strong></p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 22. <code>IfAccumulatedFileCount</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAccumulatedFileCount-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of optional nested conditions. |
| This condition matches only if <strong>all</strong> the nested conditions also match.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfAccumulatedFileCount" class="xref page">📖 Plugin reference for <code>IfAccumulatedFileCount</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfFileName"><a class="anchor" href="#IfFileName"></a><code>IfFileName</code></h4> |
| <div class="paragraph"> |
| <p>Matches files based on their path <strong>relative</strong> to the base directory.</p> |
| </div> |
| <table id="IfFileName-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 23. <code>IfFileName</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfFileName-attr-glob"></a>glob</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">String</p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Matches the path relative to the base directory using a <code>glob</code> pattern.</p> |
| <p class="tableblock">See |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String)"><code>FileSystem.getPathMatcher()</code></a> |
| for the supported <code>glob</code> syntax.</p> |
| <p class="tableblock"><strong>Required</strong>, unless <a href="#IfFileName-attr-regex"><code>regex</code></a> is specified.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfFileName-attr-regex"></a>regex</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html"><code>Pattern</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">Matches the path relative to the directory using a regular expression.</p> |
| <p class="tableblock">See |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html"><code>Pattern</code></a> |
| for the supported regular expression syntax.</p> |
| <p class="tableblock"><strong>Required</strong>, unless <a href="#IfFileName-attr-glob"><code>glob</code></a> is specified.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 24. <code>IfFileName</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfFileName-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of optional nested conditions. |
| This condition matches only if <strong>all</strong> the nested conditions also match.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfFileName" class="xref page">📖 Plugin reference for <code>IfFileName</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfLastModified"><a class="anchor" href="#IfLastModified"></a><code>IfLastModified</code></h4> |
| <div class="paragraph"> |
| <p>Accepts files based on their last modification timestamp.</p> |
| </div> |
| <table id="IfLastModified-attributes" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 25. <code>IfLastModified</code> configuration attributes</caption> |
| <colgroup> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 62.5%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Attribute</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Default value</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfLastModified-attr-age"></a>age</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/Duration.html"><code>Duration</code></a></p></td> |
| <td class="tableblock halign-left valign-top"></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The condition accepts files that are as old or older than the specified duration.</p> |
| <p class="tableblock"><strong>Required</strong></p></td> |
| </tr> |
| </tbody> |
| </table> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 26. <code>IfLastModified</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfLastModified-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">zero or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A set of optional nested conditions. |
| This condition matches only if <strong>all</strong> the nested conditions also match.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfLastModified" class="xref page">📖 Plugin reference for <code>IfLastModified</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfNot"><a class="anchor" href="#IfNot"></a><code>IfNot</code></h4> |
| <div class="paragraph"> |
| <p>Negates the result of the nested condition.</p> |
| </div> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 27. <code>IfNot</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfNot-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><strong>one</strong></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The path condition to negate.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfNot" class="xref page">📖 Plugin reference for <code>IfNot</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfAll"><a class="anchor" href="#IfAll"></a><code>IfAll</code></h4> |
| <div class="paragraph"> |
| <p>Accepts a file if all the nested conditions are true.</p> |
| </div> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 28. <code>IfAll</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAll-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">one or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The nested conditions to check.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfAll" class="xref page">📖 Plugin reference for <code>IfAll</code></a></p> |
| </div> |
| </div> |
| <div class="sect3"> |
| <h4 id="IfAny"><a class="anchor" href="#IfAny"></a><code>IfAny</code></h4> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 29. <code>IfAny</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="IfAny-element-PathCondition"></a><a href="#PathCondition"><code>PathCondition</code></a></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">one or more</p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The nested conditions to check.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-IfAny" class="xref page">📖 Plugin reference for <code>IfAny</code></a></p> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="ScriptCondition"><a class="anchor" href="#ScriptCondition"></a><code>ScriptCondition</code></h3> |
| <div class="paragraph"> |
| <p>The <code>ScriptCondition</code> uses a JSR 223 script to determine a list of matching files.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Its configuration consists of a single nested script element:</p> |
| </div> |
| <table class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 30. <code>ScriptCondition</code> nested elements</caption> |
| <colgroup> |
| <col style="width: 37.5%;"> |
| <col style="width: 12.5%;"> |
| <col style="width: 50%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Multiplicity</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../scripts.html#Script" class="xref page"><code>Script</code></a>, |
| <a href="../scripts.html#ScriptFile" class="xref page"><code>ScriptFile</code></a> |
| or |
| <a href="../scripts.html#ScriptRef" class="xref page"><code>ScriptRef</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><strong>one</strong></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">A reference to the script to execute.</p> |
| <p class="tableblock">See <a href="../scripts.html" class="xref page">Scripts</a> for more details about scripting.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p>The script must return a list of |
| <a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.html"><code>PathWithAttributes</code></a> |
| objects and supports the following bindings:</p> |
| </div> |
| <table id="ScriptFilter-bindings" class="tableblock frame-all grid-all stretch"> |
| <caption class="title">Table 31. Script Bindings</caption> |
| <colgroup> |
| <col style="width: 16.6666%;"> |
| <col style="width: 16.6666%;"> |
| <col style="width: 66.6668%;"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th class="tableblock halign-left valign-top">Binding name</th> |
| <th class="tableblock halign-left valign-top">Type</th> |
| <th class="tableblock halign-left valign-top">Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="ScriptFilter-binding-basePath"></a>basePath</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html"><code>Path</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The path of the base directory.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="ScriptFilter-binding-configuration"></a>configuration</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../configuration.html" class="xref page"><code>Configuration</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The <code>Configuration</code> object.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="ScriptFilter-binding-pathList"></a>pathList</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.html"><code>List<PathWithAttributes></code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The list of files contained in the base directory.</p> |
| <p class="tableblock">The paths are obtained by |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#resolve-java.nio.file.Path-">resolving</a> |
| the relative file names against |
| <a href="#ScriptFilter-binding-basePath"><code>basePath</code></a>.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="ScriptFilter-binding-substitutor"></a>substitutor</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/lookup/StrSubstitutor.html"><code>StrSubstitutor</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The <code>StrSubstitutor</code> used to replace lookup variables.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><a id="ScriptFilter-binding-statusLogger"></a>statusLogger</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/Logger.html"><code>Logger</code></a></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">The <a href="../status-logger.html" class="xref page">Status Logger</a> to used by diagnostic messages in the script.</p></td> |
| </tr> |
| <tr> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code><key></code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td> |
| <td class="tableblock halign-left valign-top"><p class="tableblock">If <code><key></code> is not one of the above, it will be bound to the value given by |
| <a href="../configuration.html#property-substitution" class="xref page">the global <code>Properties</code> configuration element.</a></p></td> |
| </tr> |
| </tbody> |
| </table> |
| <div class="paragraph"> |
| <p>For an example of <code>ScriptCondition</code> usage, see the <a href="#using-script-condition">Using <code>ScriptCondition</code></a> example below.</p> |
| </div> |
| <div class="paragraph"> |
| <p><a href="../../plugin-reference.html#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-appender-rolling-action-ScriptCondition" class="xref page">📖 Plugin reference for <code>ScriptCondition</code></a></p> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="recipes"><a class="anchor" href="#recipes"></a>Configuration recipes</h2> |
| <div class="sectionbody"> |
| <div class="sect2"> |
| <h3 id="logrotate-daily"><a class="anchor" href="#logrotate-daily"></a><code>logrotate</code> equivalent configuration</h3> |
| <div class="paragraph"> |
| <p><a href="https://github.com/logrotate/logrotate"><code>Logrotate</code></a> is a common UNIX utility that rotates log files.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Since a Java application cannot be notified that the log files need to be reloaded <code>logrotate</code> can be used with Java application through its <code>copytruncate</code> option (see |
| <a href="https://man7.org/linux/man-pages/man8/logrotate.8.html"><code>logrotate(8)</code> man page</a>). |
| A sample <code>logrotate</code> configuration file might therefore look like:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-none hljs">/var/log/app.log { |
| copytruncate |
| compress |
| rotate 15 |
| daily |
| maxsize 100k |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>This configuration has a problem, which is explained in the documentation of the <code>copytruncate</code> option:</p> |
| </div> |
| <div class="quoteblock"> |
| <blockquote> |
| Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. |
| </blockquote> |
| </div> |
| <div class="paragraph"> |
| <p>Fortunately you can replace the usage of <code>logrotate</code> with a rolling file appender. |
| An equivalent configuration will look like this:</p> |
| </div> |
| <div id="_tabs_3" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_3_xml" class="tab"> |
| <p>XML</p> |
| </li> |
| <li id="_tabs_3_json" class="tab"> |
| <p>JSON</p> |
| </li> |
| <li id="_tabs_3_yaml" class="tab"> |
| <p>YAML</p> |
| </li> |
| <li id="_tabs_3_properties" class="tab"> |
| <p>Properties</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_3_xml--panel" class="tabpanel" aria-labelledby="_tabs_3_xml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/logrotate.xml"><code>log4j2.xml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><RollingFile name="FILE" |
| fileName="/var/log/app.log" |
| filePattern="/var/log/app.log.%i.gz"> <i class="conum" data-value="1"></i><b>(1)</b> |
| <JsonTemplateLayout/> |
| <DefaultRolloverStrategy max="15"/> <i class="conum" data-value="2"></i><b>(2)</b> |
| <Policies> |
| <CronTriggeringPolicy schedule="0 0 0 * * ?"/> <i class="conum" data-value="3"></i><b>(3)</b> |
| <SizeBasedTriggeringPolicy size="100k"/> <i class="conum" data-value="4"></i><b>(4)</b> |
| </Policies> |
| </RollingFile></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_3_json--panel" class="tabpanel" aria-labelledby="_tabs_3_json"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/logrotate.json"><code>log4j2.json</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"RollingFile": { |
| "name": "FILE", |
| "fileName": "/var/log/app.log", |
| "filePattern": "/var/log/app.log.%i.gz", <i class="conum" data-value="1"></i><b>(1)</b> |
| "JsonTemplateLayout": {}, |
| "DefaultRolloverStrategy": { |
| "max": 15 <i class="conum" data-value="2"></i><b>(2)</b> |
| }, |
| "Policies": { |
| "CronTriggeringPolicy": { |
| "schedule": "0 0 0 * * ?" <i class="conum" data-value="3"></i><b>(3)</b> |
| }, |
| "SizeBasedTriggeringPolicy": { |
| "size": "100k" <i class="conum" data-value="4"></i><b>(4)</b> |
| } |
| } |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_3_yaml--panel" class="tabpanel" aria-labelledby="_tabs_3_yaml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/logrotate.yaml"><code>log4j2.yaml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">RollingFile: |
| name: "FILE" |
| fileName: "/var/log/app.log" |
| filePattern: "/var/log/app.log.%i.gz" <i class="conum" data-value="1"></i><b>(1)</b> |
| JsonTemplateLayout: {} |
| DefaultRolloverStrategy: |
| max: 15 <i class="conum" data-value="2"></i><b>(2)</b> |
| Policies: |
| CronTriggeringPolicy: |
| schedule: "0 0 0 * * ?" <i class="conum" data-value="3"></i><b>(3)</b> |
| SizeBasedTriggeringPolicy: |
| size: "100k" <i class="conum" data-value="4"></i><b>(4)</b></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_3_properties--panel" class="tabpanel" aria-labelledby="_tabs_3_properties"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/logrotate.properties"><code>log4j2.properties</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-properties hljs" data-lang="properties">appender.0.type = RollingFile |
| appender.0.name = FILE |
| appender.0.fileName = /var/log/app.log |
| <i class="conum" data-value="1"></i><b>(1)</b> |
| appender.0.filePattern = /var/log/app.log.%i.gz |
| |
| appender.0.layout.type = JsonTemplateLayout |
| |
| appender.0.strategy.type = DefaultRolloveStrategy |
| <i class="conum" data-value="2"></i><b>(2)</b> |
| appender.0.strategy.max = 15 |
| |
| appender.0.policy.type = Policies |
| appender.0.policy.0.type = CronTriggeringPolicy |
| <i class="conum" data-value="3"></i><b>(3)</b> |
| appender.0.policy.0.schedule = 0 0 0 * * ? |
| appender.0.policy.1.type = SizeBasedTriggeringPolicy |
| <i class="conum" data-value="4"></i><b>(4)</b> |
| appender.0.policy.1.size = 100k</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>Equivalent to <code>compress</code>: archived files are compressed.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>Equivalent to <code>rotate 15</code>: only the <code>15</code> latest log files are kept.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="3"></i><b>3</b></td> |
| <td>Equivalent to <code>daily</code>: logs will be rotated at midnight of each day.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="4"></i><b>4</b></td> |
| <td>Equivalent to <code>maxsize 100k</code>: logs will be rotated if they exceed 100 kB of size.</td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="timestamped"><a class="anchor" href="#timestamped"></a>Timestamped log file names</h3> |
| <div class="paragraph"> |
| <p>The following configuration creates one log file every day and deletes those more than 15 days old.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Since we have a <code>%d</code> pattern in the configuration file, we need to use an explicit <a href="#DeleteAction"><code>Delete</code> action</a>.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div id="_tabs_4" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_4_xml" class="tab"> |
| <p>XML</p> |
| </li> |
| <li id="_tabs_4_json" class="tab"> |
| <p>JSON</p> |
| </li> |
| <li id="_tabs_4_yaml" class="tab"> |
| <p>YAML</p> |
| </li> |
| <li id="_tabs_4_properties" class="tab"> |
| <p>Properties</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_4_xml--panel" class="tabpanel" aria-labelledby="_tabs_4_xml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/timestamped.xml"><code>log4j2.xml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><RollingFile name="FILE" |
| filePattern="/var/log/app.%d{yyyy-MM-dd}.log.gz"> <i class="conum" data-value="1"></i><b>(1)</b> |
| <JsonTemplateLayout/> |
| <DirectWriteRolloverStrategy> |
| <Delete basePath="/var/log"> <i class="conum" data-value="2"></i><b>(2)</b> |
| <IfFileName regex="app\.\d{4}-\d{2}-\d{2}\.log\.gz"/> <i class="conum" data-value="3"></i><b>(3)</b> |
| <IfLastModified age="P15D"/> |
| </Delete> |
| </DirectWriteRolloverStrategy> |
| <TimeBasedTriggeringPolicy/> |
| </RollingFile></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_4_json--panel" class="tabpanel" aria-labelledby="_tabs_4_json"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/timestamped.json"><code>log4j2.json</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"RollingFile": { |
| "name": "FILE", |
| "filePattern": "/var/log/app.%d{yyyy-MM-dd}.log.gz", <i class="conum" data-value="1"></i><b>(1)</b> |
| "JsonTemplateLayout": {}, |
| "DirectWriteRolloverStrategy": { |
| "Delete": { <i class="conum" data-value="2"></i><b>(2)</b> |
| "basePath": "/var/log", |
| "IfFileName": { |
| "regex": "app\\.\\d{4}-\\d{2}-\\d{2}\\.log\\.gz" <i class="conum" data-value="3"></i><b>(3)</b> |
| }, |
| "IfLastModified": { |
| "age": "P15D" |
| } |
| } |
| }, |
| "TimeBasedTriggeringPolicy": {} |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_4_yaml--panel" class="tabpanel" aria-labelledby="_tabs_4_yaml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/timestamped.yaml"><code>log4j2.yaml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">RollingFile: |
| name: "FILE" |
| filePattern: "/var/log/app.%d{yyyy-MM-dd}.log.gz" <i class="conum" data-value="1"></i><b>(1)</b> |
| JsonTemplateLayout: {} |
| DirectWriteRolloverStrategy: |
| Delete: <i class="conum" data-value="2"></i><b>(2)</b> |
| basePath: "/var/log" |
| IfFileName: |
| regex: "app\\.\\d{4}-\\d{2}-\\d{2}\\.log\\.gz" <i class="conum" data-value="3"></i><b>(3)</b> |
| IfLastModified: |
| age: "P15D" |
| TimeBasedTriggeringPolicy: {}</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_4_properties--panel" class="tabpanel" aria-labelledby="_tabs_4_properties"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/timestamped.properties"><code>log4j2.properties</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-properties hljs" data-lang="properties">appender.0.type = RollingFile |
| appender.0.name = FILE |
| <i class="conum" data-value="1"></i><b>(1)</b> |
| appender.0.filePattern = /var/log/app.%d{yyyy-MM-dd}.log.gz |
| |
| appender.0.layout.type = JsonTemplateLayout |
| |
| appender.0.strategy.type = DirectWriteRolloverStrategy |
| <i class="conum" data-value="2"></i><b>(2)</b> |
| appender.0.strategy.delete.type = Delete |
| appender.0.strategy.delete.basePath = /var/log |
| appender.0.strategy.delete.0.type = IfFileName |
| <i class="conum" data-value="3"></i><b>(3)</b> |
| appender.0.strategy.delete.0.regex = app\\.\\d{4}-\\d{2}-\\d{2}\\.log\\.gz |
| appender.0.strategy.delete.1.type = IfLastModified |
| appender.0.strategy.delete.1.age = P15D |
| |
| appender.0.policy.type = TimeBaseTriggeringPolicy</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>Only the <code>filePattern</code> attribute is used, since we use the <a href="#DirectWriteRolloverStrategy"><code>DirectWriteRolloverStrategy</code></a>.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>An explicit <code>Delete</code> action is provided.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="3"></i><b>3</b></td> |
| <td>You can select the files to delete using a regular expression or a simpler <code>app.*.log.gz</code> glob pattern.</td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="using-script-condition"><a class="anchor" href="#using-script-condition"></a>Using <code>ScriptCondition</code></h3> |
| <div class="paragraph"> |
| <p>If the supplied <a href="#PathCondition">path conditions</a> are not sufficient, you can use a <a href="#ScriptCondition"><code>ScriptCondition</code></a> with an arbitrary script.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The <a href="#timestamped">example above</a> can be rewritten into the following Groovy script:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/script-condition.groovy"><code>script-condition.groovy</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">def limit = FileTime.from(ZonedDateTime.now().minusDays(15).toInstant()) |
| def matcher = FileSystems.getDefault().getPathMatcher('glob:app.*.log.gz') |
| statusLogger.info("Deleting files older than {}.", limit) <i class="conum" data-value="1"></i><b>(1)</b> |
| return pathList.stream() |
| .filter({ |
| def relPath = basePath.relativize(it.path) <i class="conum" data-value="2"></i><b>(2)</b> |
| def lastModified = it.attributes.lastModifiedTime() |
| Files.isRegularFile(it.path) |
| && lastModified <= limit <i class="conum" data-value="3"></i><b>(3)</b> |
| && matcher.matches(relPath) <i class="conum" data-value="4"></i><b>(4)</b> |
| }) |
| .collect(Collectors.toList())</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>Adding <a href="../status-logger.html" class="xref page">Status Logger</a> calls in your script might help in debugging it.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td><a href="../../javadoc/log4j-core/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.html#getPath()"><code>PathWithAttributes.getPath()</code></a> |
| always starts with <code>basePath</code>, so we need to relativize it.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="3"></i><b>3</b></td> |
| <td>Equivalent to the <a href="#IfLastModified"><code>IfLastModified</code></a> condition.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="4"></i><b>4</b></td> |
| <td>Equivalent to the <a href="#IfFileName"><code>IfFileName</code></a> condition.</td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>You can use the script in your configuration file as follows:</p> |
| </div> |
| <div id="_tabs_5" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_5_xml" class="tab"> |
| <p>XML</p> |
| </li> |
| <li id="_tabs_5_json" class="tab"> |
| <p>JSON</p> |
| </li> |
| <li id="_tabs_5_yaml" class="tab"> |
| <p>YAML</p> |
| </li> |
| <li id="_tabs_5_properties" class="tab"> |
| <p>Properties</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_5_xml--panel" class="tabpanel" aria-labelledby="_tabs_5_xml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/script-condition.xml"><code>log4j2.xml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><RollingFile name="FILE" |
| filePattern="/var/log/app.%d{yyyy-MM-dd}.log.gz"> |
| <JsonTemplateLayout/> |
| <DirectWriteRolloverStrategy> |
| <Delete basePath="/var/log"> |
| <ScriptCondition> |
| <ScriptFile path="script-condition.groovy" |
| language="groovy"/> |
| </ScriptCondition> |
| </Delete> |
| </DirectWriteRolloverStrategy> |
| <TimeBasedTriggeringPolicy/> |
| </RollingFile></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_5_json--panel" class="tabpanel" aria-labelledby="_tabs_5_json"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/script-condition.json"><code>log4j2.json</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"RollingFile": { |
| "name": "FILE", |
| "filePattern": "/var/log/app.%d{yyyy-MM-dd}.log.gz", |
| "JsonTemplateLayout": {}, |
| "DirectWriteRolloverStrategy": { |
| "Delete": { |
| "basePath": "/var/log", |
| "ScriptCondition": { |
| "ScriptFile": { |
| "path": "script-condition.groovy", |
| "language": "groovy" |
| } |
| } |
| } |
| }, |
| "TimeBasedTriggeringPolicy": {} |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_5_yaml--panel" class="tabpanel" aria-labelledby="_tabs_5_yaml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/script-condition.yaml"><code>log4j2.yaml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">RollingFile: |
| name: "FILE" |
| filePattern: "/var/log/app.%d{yyyy-MM-dd}.log.gz" |
| JsonTemplateLayout: {} |
| DirectWriteRolloverStrategy: |
| Delete: |
| basePath: "/var/log" |
| ScriptCondition: |
| path: "script-condition.groovy" |
| language: "groovy" |
| TimeBasedTriggeringPolicy: {}</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_5_properties--panel" class="tabpanel" aria-labelledby="_tabs_5_properties"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/script-condition.properties"><code>log4j2.properties</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-properties hljs" data-lang="properties">appender.0.type = RollingFile |
| appender.0.name = FILE |
| appender.0.filePattern = /var/log/app.%d{yyyy-MM-dd}.log.gz |
| |
| appender.0.layout.type = JsonTemplateLayout |
| |
| appender.0.strategy.type = DirectWriteRolloverStrategy |
| appender.0.strategy.delete.type = Delete |
| appender.0.strategy.delete.basePath = /var/log |
| appender.0.strategy.delete.condition.type = ScriptCondition |
| appender.0.strategy.delete.condition.script.type = ScriptFile |
| appender.0.strategy.delete.condition.script.path = script-condition.groovy |
| appender.0.strategy.delete.condition.script.language = groovy |
| |
| appender.0.policy.type = TimeBaseTriggeringPolicy</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="per-month"><a class="anchor" href="#per-month"></a>Separate folder per month</h3> |
| <div class="paragraph"> |
| <p>We can also create separate folders for temporarily related files. |
| In the example below, we create a different folder for each month:</p> |
| </div> |
| <div id="_tabs_6" class="openblock tabs is-sync is-loading"> |
| <div class="content"> |
| <div class="ulist tablist"> |
| <ul> |
| <li id="_tabs_6_xml" class="tab"> |
| <p>XML</p> |
| </li> |
| <li id="_tabs_6_json" class="tab"> |
| <p>JSON</p> |
| </li> |
| <li id="_tabs_6_yaml" class="tab"> |
| <p>YAML</p> |
| </li> |
| <li id="_tabs_6_properties" class="tab"> |
| <p>Properties</p> |
| </li> |
| </ul> |
| </div> |
| <div id="_tabs_6_xml--panel" class="tabpanel" aria-labelledby="_tabs_6_xml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/per-month.xml"><code>log4j2.xml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml"><RollingFile name="FILE" |
| filePattern="/var/log/app/%d{yyyy-MM}/%d{yyyy-MM-dd}.log.gz"> <i class="conum" data-value="1"></i><b>(1)</b> |
| <JsonTemplateLayout/> |
| <DirectWriteRolloverStrategy> |
| <Delete basePath="/var/log/app" |
| maxDepth="2"> <i class="conum" data-value="2"></i><b>(2)</b> |
| <IfLastModified age="P90D"/> |
| </Delete> |
| </DirectWriteRolloverStrategy> |
| <TimeBasedTriggeringPolicy/> |
| </RollingFile></code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_6_json--panel" class="tabpanel" aria-labelledby="_tabs_6_json"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/per-month.json"><code>log4j2.json</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">"RollingFile": { |
| "name": "FILE", |
| "filePattern": "/var/log/app/%{yyyy-MM}/%d{yyyy-MM-dd}.log.gz", <i class="conum" data-value="1"></i><b>(1)</b> |
| "JsonTemplateLayout": {}, |
| "DirectWriteRolloverStrategy": { |
| "Delete": { |
| "basePath": "/var/log/app", |
| "maxDepth": 2, <i class="conum" data-value="2"></i><b>(2)</b> |
| "IfLastModified": { |
| "age": "P90D" |
| } |
| } |
| }, |
| "TimeBasedTriggeringPolicy": {} |
| }</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_6_yaml--panel" class="tabpanel" aria-labelledby="_tabs_6_yaml"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/per-month.yaml"><code>log4j2.yaml</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">RollingFile: |
| name: "FILE" |
| filePattern: "/var/log/app/%d{yyyy-MM}/%d{yyyy-MM-dd}.log.gz" <i class="conum" data-value="1"></i><b>(1)</b> |
| JsonTemplateLayout: {} |
| DirectWriteRolloverStrategy: |
| Delete: |
| basePath: "/var/log/app" |
| maxDepth: 2 <i class="conum" data-value="2"></i><b>(2)</b> |
| IfLastModified: |
| age: "P90D" |
| TimeBasedTriggeringPolicy: {}</code></pre> |
| </div> |
| </div> |
| </div> |
| <div id="_tabs_6_properties--panel" class="tabpanel" aria-labelledby="_tabs_6_properties"> |
| <div class="listingblock"> |
| <div class="title">Snippet from an example <a href="https://github.com/apache/logging-log4j2/tree/rel/2.25.1/src/site/antora/modules/ROOT/examples/manual/appenders/rolling-file/per-month.properties"><code>log4j2.properties</code></a></div> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-properties hljs" data-lang="properties">appender.0.type = RollingFile |
| appender.0.name = FILE |
| <i class="conum" data-value="1"></i><b>(1)</b> |
| appender.0.filePattern = /var/log/app/%d{yyyy-MM]/%d{yyyy-MM-dd}.log.gz |
| |
| appender.0.layout.type = JsonTemplateLayout |
| |
| appender.0.strategy.type = DirectWriteRolloverStrategy |
| appender.0.strategy.delete.type = Delete |
| appender.0.strategy.delete.basePath = /var/log/app |
| <i class="conum" data-value="2"></i><b>(2)</b> |
| appender.0.strategy.delete.maxDepth = 2 |
| appender.0.strategy.delete.0.type = IfLastModified |
| appender.0.strategy.delete.0.age = P90D |
| |
| appender.0.policy.type = TimeBaseTriggeringPolicy</code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>We use two <code>%d</code> patterns to specify the folder and file name.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>We increase the recursion depth of the <code>Delete</code> action to extend to subfolders of the base directory.</td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| </div> |
| </article> |
| </div> |
| </main> |
| </div> |
| <footer class="footer"> |
| <p> |
| Copyright © 1999-2025 <a href="https://www.apache.org/">The Apache Software Foundation</a>. |
| Licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache Software License, Version 2.0</a>. |
| Please read our <a href="https://privacy.apache.org/policies/privacy-policy-public.html">privacy policy</a>. |
| </p> |
| <p> |
| Apache, Log4j, and the Apache feather logo are trademarks or registered trademarks of The Apache Software Foundation. |
| Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
| Other names may be trademarks of their respective owners. |
| </p> |
| </footer> |
| <!-- Matomo --> |
| <script> |
| var _paq = window._paq = window._paq || []; |
| _paq.push(["disableCookies"]); |
| _paq.push(['trackPageView']); |
| _paq.push(['enableLinkTracking']); |
| (function() { |
| var u="https://analytics.apache.org/"; |
| _paq.push(['setTrackerUrl', u+'matomo.php']); |
| _paq.push(['setSiteId', '42']); |
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| })(); |
| </script> |
| <noscript><p><img src="https://analytics.apache.org/matomo.php?idsite=42&rec=1" style="border:0;" alt="" /></p></noscript> |
| <!-- End Matomo Code --> |
| <script id="site-script" src="../../_/js/site.js" data-ui-root-path="../../_"></script> |
| <script async src="../../_/js/vendor/highlight.js"></script> |
| <!-- `@asciidoctor/tabs` extension scripts --> |
| <script async src="../../_/js/vendor/tabs.js"></script> |
| </body> |
| </html> |