Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2403

Allow zero padding the counter of a RollingFileAppender

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.11.1
    • Fix Version/s: 2.12.0
    • Component/s: Appenders
    • Labels:
      None

      Description

      2It would be good if the filenamePattern for a RollingFileAppender would allow to zero pad the counter. Either automatically based on the max number of the counter or manually by giving the number of characters to pad to or even both approaches.

      For example the current sitution is this:
       
      {{filepattern="logs/mylog-%i.log"
      DefaultRolloverStrategy max="15"}}
       
      The files I get will be:

      {{hh-10.log.gz
      hh-11.log.gz
      hh-12.log.gz
      hh-13.log.gz
      hh-14.log.gz
      hh-15.log.gz
      hh-1.log.gz
      hh-2.log.gz
      hh-3.log.gz
      hh-4.log.gz
      hh-5.log.gz
      hh-6.log.gz
      hh-7.log.gz
      hh-8.log.gz
      hh-9.log.gz
      hh.log}}

      This is very ugly in file listings. Therefore I propose two things:

      1. Automatic padding based on the "max" parameter to the RolloverStrategy. If the max parameter has two digits (as in 15) it should automatically zero-pad the counter to be two digits as well.

      2. Manual padding based on the filepattern pattern to the RollingFileAppender. At the moment it is possible to specify this as "%05i", but this does no zero-padding as expected, but instead pads with whitespaces. It should be possible to use zero-padding here too.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hupfdule Marco Herrn
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 40m
                1h 40m