https://issues.apache.org/bugzilla/show_bug.cgi?id=57280

            Bug ID: 57280
           Summary: FileNamePattern specified as e.g. *.zip (in properties
                    file) but with trailing spaces, will result in
                    compression not occurring, yet file is renamed as
                    *.zip
           Product: Log4j
           Version: 1.2.17
          Hardware: Macintosh
                OS: Mac OS X 10.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Companions
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

My files were being rolled as per my TimeBasedRollingPolicy but when I tried to
open them, I received errors that they were invalid zip files.

Turns out that they were not zipped at all. The files had been renamed as *.zip
as per the FileNamePattern, but compression was not occurring.

In the log4j source code TimeBasedRollingPolicy.java, we see:

...

if (lastFileName.endsWith(".gz")) {
  suffixLength = 3;
} else if (lastFileName.endsWith(".zip")) {
  suffixLength = 4;
}
...

if (suffixLength == 4) {
    compressAction =
    new ZipCompressAction(
      new File(lastBaseName), new File(lastFileName), true);
}
...

My log4j.properties file had trailing spaces after the .zip in my
FileNamePattern, so the length was neither 3 or 4.

My suggestions would be:

- use trim() on the file name
- don't rename to e.g. *.zip unless compression actually occurs

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to