You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2014/11/28 20:48:54 UTC

[Bug 57280] New: 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

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: log4j-dev@logging.apache.org
          Reporter: bruno.hedman@gmail.com
                CC: log4j-dev@logging.apache.org

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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org