<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <base href="http://jira.qos.ch" /> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
            <!-- header here --> 
            <tr> 
                <td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px"> 
                    <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
                        <tr> 
                            <td id="header-avatar-image-container" valign="top" style="padding: 0px; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px"> <img id="header-avatar-image" class="image_fix" src="cid:jira-generated-image-avatar-b84db0ad-a655-4eb9-b8f3-29e2ae3d0daa" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top" /> 
                            </td> 
                            <td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="dlipofsky" id="email_dlipofsky" href="http://jira.qos.ch/secure/ViewProfile.jspa?name=dlipofsky" style="color:#3b73af;; color: #3b73af; text-decoration: none">Dan Lipofsky</a> <strong>commented</strong> on <a href="http://jira.qos.ch/browse/LOGBACK-204" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-static-newfeature-a8c3caeb-5507-4c68-857f-19a288fa15d8" height="16" width="16" border="0" align="absmiddle" alt="New Feature" /> LOGBACK-204</a> 
                            </td> 
                        </tr> 
                    </table> 
                </td> 
            </tr> 
            <tr> 
                <td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px"> 
                    <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0; border-collapse: separate"> 
                        <tr> 
                            <!-- there needs to be content in the cell for it to render in some clients --> 
                            <td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 15px; background-color: #fff; border-left: 1px solid #ccc; border-top: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly">
                                 
                            </td> 
                        </tr> 
                        <tr> 
                            <td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff"> 
                                <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
                                    <tr> 
                                        <td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="http://jira.qos.ch/browse/LOGBACK-204" style="color: #3b73af; text-decoration: none">Re: file appender that rolls on startup</a> </span> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td id="text-paragraph-pattern-top" class="email-content-main mobile-expand  comment-top-pattern" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff; border-bottom: none; padding-bottom: 0"> 
                                <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                    <tr> 
                                        <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0px; border-collapse: collapse; padding: 0 0 10px 0"> 
                                            <p style="margin: 10px 0 0 0">I'd still like to see this implemented internally, but I did find a solution. It involves separating the rolling and triggering policies. If anyone has code review feedback for me, I'd welcome it.</p> 
                                            <p style="margin: 10px 0 0 0">I wanted to roll on startup and roll on size, but not time. This does it:</p> 
                                            <div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
                                                <div class="codeContent panelContent" style="padding: 9px 12px"> 
                                                    <pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
<span class="code-keyword" style="color: #000091">public</span> class RollOnStartupAndSizeTriggeringPolicy<E> <span class="code-keyword" style="color: #000091">extends</span> SizeBasedTriggeringPolicy<E> {
    <span class="code-keyword" style="color: #000091">private</span> <span class="code-keyword" style="color: #000091">final</span> AtomicBoolean firstTime = <span class="code-keyword" style="color: #000091">new</span> AtomicBoolean();

    <span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">boolean</span> isTriggeringEvent(<span class="code-keyword" style="color: #000091">final</span> File activeFile, <span class="code-keyword" style="color: #000091">final</span> E event) {
        <span class="code-keyword" style="color: #000091">if</span> (firstTime.compareAndSet(<span class="code-keyword" style="color: #000091">false</span>, <span class="code-keyword" style="color: #000091">true</span>) && activeFile != <span class="code-keyword" style="color: #000091">null</span> && activeFile.length() > 0) {
            <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">true</span>;
        }
        <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">super</span>.isTriggeringEvent(activeFile, event);
    }
}
</pre> 
                                                </div>
                                            </div> 
                                            <p style="margin: 10px 0 0 0">With this you also need a rolling policy. FixedWindowRollingPolicy would probably do, but I don't like it because I want to keep a large number of files and it is very inefficient for that. Something that numbers incrementally up (instead of sliding like FixedWindow) would work, but that doesn't exist. As long as I am writing my own I decided to use time instead of count. I wanted to extend current logback code, but for the time based stuff the rolling and triggering policies are combined into one class, and there is lots of nesting and circular stuff and fields with no getters, so I found that rather impossible. So I had to do a lot from scratch. I keep it simple and didn't implement features like compression - I'd love to have them but I am just trying to keep it simple.</p> 
                                            <div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
                                                <div class="codeContent panelContent" style="padding: 9px 12px"> 
                                                    <pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
<span class="code-keyword" style="color: #000091">public</span> class TimestampRollingPolicy<E> <span class="code-keyword" style="color: #000091">extends</span> RollingPolicyBase {
    <span class="code-keyword" style="color: #000091">private</span> <span class="code-keyword" style="color: #000091">final</span> RenameUtil renameUtil = <span class="code-keyword" style="color: #000091">new</span> RenameUtil();
    <span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> activeFileName;
    <span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> fileNamePatternStr;
    <span class="code-keyword" style="color: #000091">private</span> FileNamePattern fileNamePattern;

    @Override
    <span class="code-keyword" style="color: #000091">public</span> void start() {
        <span class="code-keyword" style="color: #000091">super</span>.start();
        renameUtil.setContext(<span class="code-keyword" style="color: #000091">this</span>.context);
        activeFileName = getParentsRawFileProperty();
        <span class="code-keyword" style="color: #000091">if</span> (activeFileName == <span class="code-keyword" style="color: #000091">null</span> || activeFileName.isEmpty()) {
            addError(<span class="code-quote" style="color: #009100">"No file set on appender"</span>);
        }
        <span class="code-keyword" style="color: #000091">if</span> (fileNamePatternStr == <span class="code-keyword" style="color: #000091">null</span> || fileNamePatternStr.isEmpty()) {
            addError(<span class="code-quote" style="color: #009100">"fileNamePattern not set"</span>);
            fileNamePattern = <span class="code-keyword" style="color: #000091">null</span>;
        } <span class="code-keyword" style="color: #000091">else</span> {
            fileNamePattern = <span class="code-keyword" style="color: #000091">new</span> FileNamePattern(fileNamePatternStr, <span class="code-keyword" style="color: #000091">this</span>.context);
        }
        addInfo(<span class="code-quote" style="color: #009100">"Will use the pattern "</span> + fileNamePattern + <span class="code-quote" style="color: #009100">" to archive files"</span>);
    }

    @Override
    <span class="code-keyword" style="color: #000091">public</span> void rollover() <span class="code-keyword" style="color: #000091">throws</span> RolloverFailure {
        File f = <span class="code-keyword" style="color: #000091">new</span> File(activeFileName);
        <span class="code-keyword" style="color: #000091">if</span> (!f.exists()) {
            <span class="code-keyword" style="color: #000091">return</span>;
        }
        <span class="code-keyword" style="color: #000091">if</span> (f.length() <= 0) {
            <span class="code-keyword" style="color: #000091">return</span>;
        }
        <span class="code-keyword" style="color: #000091">try</span> {
            <span class="code-object" style="color: #910091">String</span> archiveFileName = fileNamePattern.convert(<span class="code-keyword" style="color: #000091">new</span> Date(f.lastModified()));
            renameUtil.rename(activeFileName, archiveFileName);
        } <span class="code-keyword" style="color: #000091">catch</span> (RolloverFailure e) {
            <span class="code-keyword" style="color: #000091">throw</span> e;
        } <span class="code-keyword" style="color: #000091">catch</span> (Exception e) {
            <span class="code-keyword" style="color: #000091">throw</span> <span class="code-keyword" style="color: #000091">new</span> RolloverFailure(e.toString(), e);
        }
    }

    @Override
    <span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getActiveFileName() {
        <span class="code-keyword" style="color: #000091">return</span> activeFileName;
    }

    <span class="code-keyword" style="color: #000091">public</span> void setFileNamePattern(<span class="code-object" style="color: #910091">String</span> fnp) {
        fileNamePatternStr = fnp;
    }
}
</pre> 
                                                </div>
                                            </div> 
                                            <p style="margin: 10px 0 0 0">And then config looks like</p> 
                                            <div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
                                                <div class="codeContent panelContent" style="padding: 9px 12px"> 
                                                    <pre class="code-xml" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
  <span class="code-tag" style="color: #000091"><appender name=<span class="code-quote" style="color: #009100">"FILE"</span> class=<span class="code-quote" style="color: #009100">"ch.qos.logback.core.rolling.RollingFileAppender"</span>></span>
    <span class="code-tag" style="color: #000091"><encoder></span>
      <span class="code-tag" style="color: #000091"><pattern></span>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="code-tag" style="color: #000091"></pattern></span>
    <span class="code-tag" style="color: #000091"></encoder></span>
    <span class="code-tag" style="color: #000091"><file></span>/tmp/monitor.log<span class="code-tag" style="color: #000091"></file></span>
    <span class="code-tag" style="color: #000091"><rollingPolicy class=<span class="code-quote" style="color: #009100">"my.log.TimestampRollingPolicy"</span>></span>
      <span class="code-tag" style="color: #000091"><fileNamePattern></span>/tmp/monitor.%d{yyyyMMdd-HHmmss}.log<span class="code-tag" style="color: #000091"></fileNamePattern></span>
    <span class="code-tag" style="color: #000091"></rollingPolicy></span>
    <span class="code-tag" style="color: #000091"><triggeringPolicy class=<span class="code-quote" style="color: #009100">"my.log.RollOnStartupAndSizeTriggeringPolicy"</span>></span>
      <span class="code-tag" style="color: #000091"><maxFileSize></span>1gb<span class="code-tag" style="color: #000091"></maxFileSize></span>
    <span class="code-tag" style="color: #000091"></triggeringPolicy></span>
  <span class="code-tag" style="color: #000091"></appender></span>
</pre> 
                                                </div>
                                            </div> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff"> 
                                <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                    <tr> 
                                        <td id="actions-pattern-container" valign="middle" style="padding: 0px; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                            <table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
                                                <tr> 
                                                    <td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"> <a href="http://jira.qos.ch/browse/LOGBACK-204#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-4efeeffe-c4ca-4f06-a0a8-7d52fcd5fa94" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle" /> </a> 
                                                    </td> 
                                                    <td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="http://jira.qos.ch/browse/LOGBACK-204#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> 
                                                    </td> 
                                                </tr> 
                                            </table> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                        <!-- there needs to be content in the cell for it to render in some clients --> 
                        <tr> 
                            <td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #fff; border-top: 0; border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly">
                                 
                            </td> 
                        </tr> 
                    </table> 
                </td> 
            </tr> 
            <tr> 
                <td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px"> 
                    <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
                        <tr> 
                            <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
                                 This message was sent by Atlassian JIRA <span id="footer-build-information">(v6.4.12#64027-<span title="e3691cc1283c0f3cef6d65d3ea82d47743692b57" data-commit-id="e3691cc1283c0f3cef6d65d3ea82d47743692b57}">sha1:e3691cc</span>)</span> 
                            </td> 
                            <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0px; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                <table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt"> 
                                    <tr> 
                                        <td id="footer-pattern-logo-desktop-padding" style="padding: 0px; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-932fd567-3832-47e0-b887-45d0e0e092f3" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix" /> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                    </table> 
                </td> 
            </tr> 
        </table>   
    </body>
</html>