-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix prudent mode OverlappingFileLockException, LOGBACK-1754
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
7 changed files
with
313 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Logback: the reliable, generic, fast and flexible logging framework. | ||
~ Copyright (C) 1999-2023, QOS.ch. All rights reserved. | ||
~ | ||
~ This program and the accompanying materials are dual-licensed under | ||
~ either the terms of the Eclipse Public License v1.0 as published by | ||
~ the Eclipse Foundation | ||
~ | ||
~ or (per the licensee's choosing) | ||
~ | ||
~ under the terms of the GNU Lesser General Public License version 2.1 | ||
~ as published by the Free Software Foundation. | ||
--> | ||
|
||
<configuration debug="true"> | ||
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> | ||
|
||
<appender name="GENERAL" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<fileNamePattern>${logback_1754_targetDirectory}/test-%d{yyyy-MM-dd}.log</fileNamePattern> | ||
<maxHistory>120</maxHistory> | ||
</rollingPolicy> | ||
<encoder> | ||
<pattern>%date{HH:mm:ss.SSS} [%level] %logger{0} [%thread] [%class{3}:%line] : %msg%n</pattern> | ||
</encoder> | ||
<prudent>true</prudent> | ||
</appender> | ||
<root level="debug"> | ||
<appender-ref ref="GENERAL" /> | ||
</root> | ||
</configuration> |
93 changes: 93 additions & 0 deletions
93
logback-classic/src/test/java/ch/qos/logback/classic/issue/logback_1754/SafeModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2023, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
|
||
package ch.qos.logback.classic.issue.logback_1754; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import ch.qos.logback.classic.ClassicConstants; | ||
import ch.qos.logback.classic.ClassicTestConstants; | ||
import ch.qos.logback.core.testUtil.RandomUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SafeModeTest { | ||
|
||
private static final int THREADS = 3; | ||
|
||
private void runTest() { | ||
|
||
CountDownLatch latch = new CountDownLatch(THREADS); | ||
List<Thread> threads = new ArrayList<>(THREADS); | ||
for (int i = 0; i < THREADS; i++) { | ||
LoggerThread thread = new LoggerThread(latch, "message from thread " + i); | ||
thread.start(); | ||
threads.add(thread); | ||
} | ||
int i = 0; | ||
for (Thread thread : threads) { | ||
try { | ||
thread.join(); | ||
System.out.println("joined thread "+thread.getName()); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
//Thread.currentThread().interrupt(); | ||
//throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String... args) { | ||
int diff = RandomUtil.getPositiveInt(); | ||
//System.setProperty("logback.statusListenerClass", "sysout"); | ||
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, ClassicTestConstants.INPUT_PREFIX+"issue/logback-1754.xml"); | ||
System.setProperty("logback_1754_targetDirectory", ClassicTestConstants.OUTPUT_DIR_PREFIX+"safeWrite_"+diff); | ||
|
||
|
||
new SafeModeTest().runTest(); | ||
} | ||
|
||
private static final class LoggerThread extends Thread { | ||
private static final Logger LOG = LoggerFactory.getLogger(LoggerThread.class); | ||
private final CountDownLatch latch; | ||
private final String message; | ||
|
||
LoggerThread(CountDownLatch latch, String message) { | ||
setDaemon(false); | ||
this.latch = latch; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
latch.countDown(); | ||
for(int i = 0; i < 100; i++) { | ||
if(i % 10 == 0) { | ||
delay(1); | ||
} | ||
LOG.info(message + " i=" + i); | ||
} | ||
} | ||
|
||
static void delay(long millis) { | ||
try { | ||
Thread.sleep(millis); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.