[ 
https://issues.apache.org/jira/browse/LOG4J2-3090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17342265#comment-17342265
 ] 

jasonyu edited comment on LOG4J2-3090 at 5/11/21, 3:09 AM:
-----------------------------------------------------------

 
{code:java}
 try (final FileInputStream fis = new FileInputStream(source);
 final FileOutputStream fos = new FileOutputStream(destination);
 final OutputStream gzipOut = new ConfigurableLevelGZIPOutputStream(
 fos, BUF_SIZE, compressionLevel);
 // Reduce native invocations by buffering data into GZIPOutputStream
 final OutputStream os = new BufferedOutputStream(gzipOut, BUF_SIZE)) {
 final byte[] inbuf = new byte[BUF_SIZE];
 int n;

 while ((n = fis.read(inbuf)) != -1) {
 os.write(inbuf, 0, n);
 }
// flush and sync
os.flush();
fos.getFD.sync();
}
{code}
 


was (Author: jasonyu):
 
{code:java}
 try (final FileInputStream fis = new FileInputStream(source);
 final OutputStream fos = new FileOutputStream(destination);
 final OutputStream gzipOut = new ConfigurableLevelGZIPOutputStream(
 fos, BUF_SIZE, compressionLevel);
 // Reduce native invocations by buffering data into GZIPOutputStream
 final OutputStream os = new BufferedOutputStream(gzipOut, BUF_SIZE)) {
 final byte[] inbuf = new byte[BUF_SIZE];
 int n;

 while ((n = fis.read(inbuf)) != -1) {
 os.write(inbuf, 0, n);
 }
// flush and sync
os.flush();
fos.getFD.sync();
}
{code}
 

> Why the log file was deleted when the compressd file has not been flushed to 
> the disk?
> --------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3090
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3090
>             Project: Log4j 2
>          Issue Type: Question
>    Affects Versions: 2.13.3
>            Reporter: jasonyu
>            Priority: Minor
>
> Here is the situation : 
> 1、The appender is RollingFileAppender with SizeBasedTriaggeringPolicy, the 
> rolling file pattern is extended to ".gz".
> 2、While the log4j2 executing rolling(compress) event, the linux server is 
> rebooted by coincidence.
> As a result, the log file before rolling was deleted and the size of the 
> compressed file was zero, which means the log message was lost.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to