Log4j2 DefaultRolloverStrategy Configuration deletes log files but not empty folders



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm using log4j2 for my app logs, I'm using XML and the configuration below is for the logs. I am storing logs in folders named after the current date. Every day a new folder is created with a name say '2018-11-15' and logs are stored into it. The code deletes the log files according to the size and age but does not delete the empty folders(2018-11-15) after these files are deleted from the folder.



<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Properties>
<Property name="baseDir">logs</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="$baseDir/app.log"
filePattern="$baseDir/$$date:yyyy-MM/app-%dyyyy-MM-dd-HH-%i.log.gz">
<PatternLayout pattern="%d %p %c1. [%t] %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
<DefaultRolloverStrategy max="100">
<!--
Nested conditions: the inner condition is only evaluated on files
for which the outer conditions are true.
-->
<Delete basePath="$baseDir" maxDepth="2">
<IfFileName glob="*/app-*.log.gz">
<IfLastModified age="30d">
<IfAny>
<IfAccumulatedFileSize exceeds="100 GB" />
<IfAccumulatedFileCount exceeds="10" />
</IfAny>
</IfLastModified>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>


How do I delete the folders once all the files inside it are deleted?
Thanx!










share|improve this question




























    0















    I'm using log4j2 for my app logs, I'm using XML and the configuration below is for the logs. I am storing logs in folders named after the current date. Every day a new folder is created with a name say '2018-11-15' and logs are stored into it. The code deletes the log files according to the size and age but does not delete the empty folders(2018-11-15) after these files are deleted from the folder.



    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn" name="MyApp" packages="">
    <Properties>
    <Property name="baseDir">logs</Property>
    </Properties>
    <Appenders>
    <RollingFile name="RollingFile" fileName="$baseDir/app.log"
    filePattern="$baseDir/$$date:yyyy-MM/app-%dyyyy-MM-dd-HH-%i.log.gz">
    <PatternLayout pattern="%d %p %c1. [%t] %m%n" />
    <Policies>
    <TimeBasedTriggeringPolicy />
    <SizeBasedTriggeringPolicy size="250 MB"/>
    </Policies>
    <DefaultRolloverStrategy max="100">
    <!--
    Nested conditions: the inner condition is only evaluated on files
    for which the outer conditions are true.
    -->
    <Delete basePath="$baseDir" maxDepth="2">
    <IfFileName glob="*/app-*.log.gz">
    <IfLastModified age="30d">
    <IfAny>
    <IfAccumulatedFileSize exceeds="100 GB" />
    <IfAccumulatedFileCount exceeds="10" />
    </IfAny>
    </IfLastModified>
    </IfFileName>
    </Delete>
    </DefaultRolloverStrategy>
    </RollingFile>
    </Appenders>
    <Loggers>
    <Root level="error">
    <AppenderRef ref="RollingFile"/>
    </Root>
    </Loggers>
    </Configuration>


    How do I delete the folders once all the files inside it are deleted?
    Thanx!










    share|improve this question
























      0












      0








      0








      I'm using log4j2 for my app logs, I'm using XML and the configuration below is for the logs. I am storing logs in folders named after the current date. Every day a new folder is created with a name say '2018-11-15' and logs are stored into it. The code deletes the log files according to the size and age but does not delete the empty folders(2018-11-15) after these files are deleted from the folder.



      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp" packages="">
      <Properties>
      <Property name="baseDir">logs</Property>
      </Properties>
      <Appenders>
      <RollingFile name="RollingFile" fileName="$baseDir/app.log"
      filePattern="$baseDir/$$date:yyyy-MM/app-%dyyyy-MM-dd-HH-%i.log.gz">
      <PatternLayout pattern="%d %p %c1. [%t] %m%n" />
      <Policies>
      <TimeBasedTriggeringPolicy />
      <SizeBasedTriggeringPolicy size="250 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="100">
      <!--
      Nested conditions: the inner condition is only evaluated on files
      for which the outer conditions are true.
      -->
      <Delete basePath="$baseDir" maxDepth="2">
      <IfFileName glob="*/app-*.log.gz">
      <IfLastModified age="30d">
      <IfAny>
      <IfAccumulatedFileSize exceeds="100 GB" />
      <IfAccumulatedFileCount exceeds="10" />
      </IfAny>
      </IfLastModified>
      </IfFileName>
      </Delete>
      </DefaultRolloverStrategy>
      </RollingFile>
      </Appenders>
      <Loggers>
      <Root level="error">
      <AppenderRef ref="RollingFile"/>
      </Root>
      </Loggers>
      </Configuration>


      How do I delete the folders once all the files inside it are deleted?
      Thanx!










      share|improve this question














      I'm using log4j2 for my app logs, I'm using XML and the configuration below is for the logs. I am storing logs in folders named after the current date. Every day a new folder is created with a name say '2018-11-15' and logs are stored into it. The code deletes the log files according to the size and age but does not delete the empty folders(2018-11-15) after these files are deleted from the folder.



      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp" packages="">
      <Properties>
      <Property name="baseDir">logs</Property>
      </Properties>
      <Appenders>
      <RollingFile name="RollingFile" fileName="$baseDir/app.log"
      filePattern="$baseDir/$$date:yyyy-MM/app-%dyyyy-MM-dd-HH-%i.log.gz">
      <PatternLayout pattern="%d %p %c1. [%t] %m%n" />
      <Policies>
      <TimeBasedTriggeringPolicy />
      <SizeBasedTriggeringPolicy size="250 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="100">
      <!--
      Nested conditions: the inner condition is only evaluated on files
      for which the outer conditions are true.
      -->
      <Delete basePath="$baseDir" maxDepth="2">
      <IfFileName glob="*/app-*.log.gz">
      <IfLastModified age="30d">
      <IfAny>
      <IfAccumulatedFileSize exceeds="100 GB" />
      <IfAccumulatedFileCount exceeds="10" />
      </IfAny>
      </IfLastModified>
      </IfFileName>
      </Delete>
      </DefaultRolloverStrategy>
      </RollingFile>
      </Appenders>
      <Loggers>
      <Root level="error">
      <AppenderRef ref="RollingFile"/>
      </Root>
      </Loggers>
      </Configuration>


      How do I delete the folders once all the files inside it are deleted?
      Thanx!







      java xml logging log4j log4j2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 16:16









      apurva sawantapurva sawant

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You don't have a build in option in log4j2 for deleting empty folders. You can check this StackOverflow answer, and this log4j2 issues discussion.



          I would say the easiest way to handle this is to run a cron regardless to the log4j configuration. I use crontab.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323640%2flog4j2-defaultrolloverstrategy-configuration-deletes-log-files-but-not-empty-fol%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You don't have a build in option in log4j2 for deleting empty folders. You can check this StackOverflow answer, and this log4j2 issues discussion.



            I would say the easiest way to handle this is to run a cron regardless to the log4j configuration. I use crontab.






            share|improve this answer



























              0














              You don't have a build in option in log4j2 for deleting empty folders. You can check this StackOverflow answer, and this log4j2 issues discussion.



              I would say the easiest way to handle this is to run a cron regardless to the log4j configuration. I use crontab.






              share|improve this answer

























                0












                0








                0







                You don't have a build in option in log4j2 for deleting empty folders. You can check this StackOverflow answer, and this log4j2 issues discussion.



                I would say the easiest way to handle this is to run a cron regardless to the log4j configuration. I use crontab.






                share|improve this answer













                You don't have a build in option in log4j2 for deleting empty folders. You can check this StackOverflow answer, and this log4j2 issues discussion.



                I would say the easiest way to handle this is to run a cron regardless to the log4j configuration. I use crontab.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 19:32









                Gal SGal S

                767415




                767415





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323640%2flog4j2-defaultrolloverstrategy-configuration-deletes-log-files-but-not-empty-fol%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20