logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
March 2011
- 6 participants
- 85 discussions
I am looking at the treatment of the prudent mode in FileAppender.java and I am seeing a potential defect.
This implementation performs a file lock followed by lock synchronization. This ordering seems to be reversed.
The behavior of concurrent file lock requests to the same file within a JVM is undefined. You need to do the
synchronization first to avoid the undefined behavior.
In fact, to workaround for the possibility of multiple loggers targeting the same file, the lock object should be the interned string of
the canonical path. That seems to be the requirements for our use-case.
Regards,
Thomas
____________________________________________________________
Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4
1
0

[JIRA] Created: (LBCLASSIC-258) Support expression evaluation in scan attribute
by Stevo Slavic (JIRA) 25 Mar '11
by Stevo Slavic (JIRA) 25 Mar '11
25 Mar '11
Support expression evaluation in scan attribute
-----------------------------------------------
Key: LBCLASSIC-258
URL: http://jira.qos.ch/browse/LBCLASSIC-258
Project: logback-classic
Issue Type: New Feature
Components: joran
Affects Versions: 0.9.28
Reporter: Stevo Slavic
Assignee: Logback dev list
At the moment (logback-classic 0.9.28) processScanAttrib method in ConfigurationAction only checks if scan attribute is not empty and if it's not equal to false (so true, but also any non empty string other than false) is enough to enable configuration changes scanning.
Please add support for expression evaluation (like here: http://logback.qos.ch/manual/configuration.html#conditional ) in scan attribute for the same reason conditional processing of configuration files has been added - so single configuration file can be used in different environments.
E.g. I'd like to configure scan attribute with following expression:
<configuration scan='property("app.env").equals("production")' scanPeriod='300 seconds'>
If janino is not on classpath, same logic can remain for backward compatibility. If janino library is on classpath, and scan is not empty, evaluation should occur - if scan attribute value evaluates to true, only then scanning should be enabled; if scan is not empty and evaluates to false, scanning should not be enabled; if scan is not empty and evaluates to neither true nor false, or exception is thrown, error should be logged.
This would break backward compatibility only for users which configured scan attribute with non-empty value, which is neither "true" nor "false".
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
1
0

[JIRA] Created: (LBCORE-166) RenameUtil not truncating file if delete fails during rollover
by Jose David Barrio (JIRA) 18 Mar '11
by Jose David Barrio (JIRA) 18 Mar '11
18 Mar '11
RenameUtil not truncating file if delete fails during rollover
--------------------------------------------------------------
Key: LBCORE-166
URL: http://jira.qos.ch/browse/LBCORE-166
Project: logback-core
Issue Type: Bug
Components: Rolling
Affects Versions: 0.9.24
Environment: Microsoft Windows XP SP2
OAS 10.1.3.4
Java 1.5.0_14
Reporter: Jose David Barrio
Assignee: Logback dev list
Priority: Minor
Attachments: RenameUtil.patch
When using logback under Windows over Oracle Application Server, if you redeploy the web application, the log file is keep open by some reason so when a new rollover happens it fails to rename the log file.
Currently RenameUtil does:
- Try to rename log file.
- If rename fails then rename by copy (copy plus delete).
If for some reason deletion fails the log file keeps all its content so I just added a truncate if deletion fails:
- Try to rename log file.
- If rename fails then rename by copy (copy plus delete).
- If delete fails then truncate file.
I do have a patch file if it's useful.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
3
7

[JIRA] Created: (LBCORE-201) RollingCalendar test fails in logback-core
by Kostya Gribov (JIRA) 18 Mar '11
by Kostya Gribov (JIRA) 18 Mar '11
18 Mar '11
RollingCalendar test fails in logback-core
------------------------------------------
Key: LBCORE-201
URL: http://jira.qos.ch/browse/LBCORE-201
Project: logback-core
Issue Type: Bug
Components: Rolling
Affects Versions: 0.9.28, 0.9.29
Environment: Linux unterwelt 2.6.37-ARCH #1 SMP PREEMPT Tue Mar 8 08:34:35 CET 2011 x86_64 Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz GenuineIntel GNU/Linux
Sun JVM: java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
Apache Maven 3.0.2
Reporter: Kostya Gribov
Assignee: Logback dev list
Attachments: ch.qos.logback.core.rolling.helper.RollingCalendarTest.txt
One of test fails in released 0.9.28 and 0.9.29-SNAPSHOT (commit 0cc65fce and HEAD commit):
testVaryingNumberOfDailyPeriods(ch.qos.logback.core.rolling.helper.RollingCalendarTest)
Surefire report in attach.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
1
1

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-27-gebb58bb
by git-noreply@pixie.qos.ch 18 Mar '11
by git-noreply@pixie.qos.ch 18 Mar '11
18 Mar '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via ebb58bb6ea3816a4e4ffd805b722c8121bba61a6 (commit)
from 5be4443a22e7f8b886b867a29c141432179c1d53 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=ebb58bb6ea3816a4e4ffd805…
http://github.com/ceki/logback/commit/ebb58bb6ea3816a4e4ffd805b722c8121bba6…
commit ebb58bb6ea3816a4e4ffd805b722c8121bba61a6
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Fri Mar 18 15:14:14 2011 +0100
fixing LBCLASSIC-255
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
index cfa963f..7715f66 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
@@ -13,17 +13,19 @@
*/
package ch.qos.logback.classic.turbo;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
+/**
+ * Clients of this class should only use the {@link #getMessageCountAndThenIncrement} method. Other methods inherited
+ * via LinkedHashMap are not thread safe.
+ */
class LRUMessageCache extends LinkedHashMap<String, Integer> {
- // LinkedHashMap permits null elements to be inserted
-
private static final long serialVersionUID = 1L;
-
final int cacheSize;
-
+
LRUMessageCache(int cacheSize) {
super((int) (cacheSize * (4.0f / 3)), 0.75f, true);
if (cacheSize < 1) {
@@ -31,24 +33,35 @@ class LRUMessageCache extends LinkedHashMap<String, Integer> {
}
this.cacheSize = cacheSize;
}
-
+
int getMessageCountAndThenIncrement(String msg) {
// don't insert null elements
- if(msg == null) {
+ if (msg == null) {
return 0;
}
-
- Integer i = super.get(msg);
- if(i == null) {
- i = 0;
- } else {
- i = new Integer(i.intValue()+1);
+
+ Integer i;
+ // LinkedHashMap is not LinkedHashMap. See also LBCLASSIC-255
+ synchronized (this) {
+ i = super.get(msg);
+ if (i == null) {
+ i = 0;
+ } else {
+ i = new Integer(i.intValue() + 1);
+ }
+ super.put(msg, i);
}
- super.put(msg, i);
return i;
}
-
+
+ // called indirectly by get() or put() which are already supposed to be
+ // called from within a synchronized block
protected boolean removeEldestEntry(Map.Entry eldest) {
return (size() > cacheSize);
}
+
+ @Override
+ synchronized public void clear() {
+ super.clear();
+ }
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
index 5e2fed3..453d0b8 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
@@ -13,8 +13,6 @@ import junit.framework.Assert;
import org.junit.Test;
public class LRUMessageCacheTest {
- private static final int INVOCATIONS_PER_TASK = 500 * 1024;
- private static final int THREADS_NUMBER = 16;
@Test
public void testEldestEntriesRemoval() {
@@ -35,46 +33,4 @@ public class LRUMessageCacheTest {
Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("2"));
}
- @Test
- public void multiThreadsTest() throws InterruptedException, ExecutionException {
- final LRUMessageCache cache = new LRUMessageCache(THREADS_NUMBER);
-
- ArrayList<TestTask> tasks = new ArrayList<TestTask>(THREADS_NUMBER);
- for (int i = 0; i < THREADS_NUMBER; i++) {
- tasks.add(new TestTask(cache));
- }
-
- ExecutorService execSrv = Executors.newFixedThreadPool(THREADS_NUMBER);
-
- List<Future<Boolean>> futures = execSrv.invokeAll(tasks);
- for (Future<Boolean> future : futures) {
- // Validate that task has successfully finished.
- future.get();
- }
- }
-
- /**
- * Each thread is using always the same "Message" key.
- */
- private class TestTask implements Callable<Boolean> {
- private int prevValue = -1;
- private final LRUMessageCache cache;
-
- public TestTask(LRUMessageCache cache) {
- this.cache = cache;
- }
-
- public Boolean call() throws Exception {
- String msg = Thread.currentThread().getName();
-
- for (int i = 0; i < INVOCATIONS_PER_TASK; i++) {
- int current = cache.getMessageCountAndThenIncrement(msg);
- // Ensure that new count is greater than previous count.
- Assert.assertEquals(prevValue + 1, current);
- prevValue = current;
- }
-
- return true;
- }
- }
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
index 980ab2e..45ee86a 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
@@ -17,7 +17,7 @@ public class T_Entry<K> implements Comparable {
K k;
long sequenceNumber;
-
+
T_Entry(K k, long sn) {
this.k = k;
this.sequenceNumber = sn;
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
index ebb7150..36d56b3 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
@@ -79,7 +79,8 @@ public class T_LRUCache<K> {
}
return null;
}
-
+
+
public void dump() {
System.out.print("T:");
for (T_Entry<K> te : cacheList) {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/X_LRUCache.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/X_LRUCache.java
new file mode 100644
index 0000000..1a51573
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/X_LRUCache.java
@@ -0,0 +1,51 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An lru cache based on Java's LinkedHashMap.
+ *
+ * @author Ceki Gulcu
+ *
+ * @param <K>
+ * @param <V>
+ */
+public class X_LRUCache<K, V> extends LinkedHashMap<K, V> {
+ private static final long serialVersionUID = -6592964689843698200L;
+
+ final int cacheSize;
+
+ public X_LRUCache(int cacheSize) {
+ super((int) (cacheSize*(4.0f/3)), 0.75f, true);
+ if(cacheSize < 1) {
+ throw new IllegalArgumentException("Cache size cannnot be smaller than 1");
+ }
+ this.cacheSize = cacheSize;
+ }
+
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return (size() > cacheSize);
+ }
+
+ List<K> keyList() {
+ ArrayList<K> al = new ArrayList<K>();
+ al.addAll(keySet());
+ return al;
+ }
+}
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 2cb6553..13d7670 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -55,6 +55,10 @@
href="http://jira.qos.ch/browse/LBCORE-193">LBCORE-193</a>
reported by B. K. Oxley.</p>
+ <p>Fixed thread safety issue in LRUMessageCache reported in <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-255">LBCLASSIC-255</a>
+ by César Álvarez Núñez.
+ </p>
<hr width="80%" align="center" />
-----------------------------------------------------------------------
Summary of changes:
.../qos/logback/classic/turbo/LRUMessageCache.java | 41 +++++---
.../logback/classic/turbo/LRUMessageCacheTest.java | 44 ---------
.../ch/qos/logback/classic/turbo/lru/T_Entry.java | 2 +-
.../qos/logback/classic/turbo/lru/T_LRUCache.java | 3 +-
.../turbo/lru/{LRUCache.java => X_LRUCache.java} | 102 ++++++++++----------
logback-site/src/site/pages/news.html | 4 +
6 files changed, 85 insertions(+), 111 deletions(-)
copy logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/{LRUCache.java => X_LRUCache.java} (89%)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0

[JIRA] Created: (LBCLASSIC-255) LRUMessageCache is not multithread-safe.
by César Álvarez Núñez (JIRA) 18 Mar '11
by César Álvarez Núñez (JIRA) 18 Mar '11
18 Mar '11
LRUMessageCache is not multithread-safe.
----------------------------------------
Key: LBCLASSIC-255
URL: http://jira.qos.ch/browse/LBCLASSIC-255
Project: logback-classic
Issue Type: Bug
Affects Versions: unspecified
Reporter: César Álvarez Núñez
Assignee: Logback dev list
Attachments: Added+synchronization+to+LRUMessageCache.+Now+it+is+multithread-safe.patch
The LRUMessageCache used on DuplicateMessageFilter is not properly synchronized.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
2
4

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-26-g5be4443
by git-noreply@pixie.qos.ch 17 Mar '11
by git-noreply@pixie.qos.ch 17 Mar '11
17 Mar '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 5be4443a22e7f8b886b867a29c141432179c1d53 (commit)
from d88160e448083dcf5524bf926b45b91cf4ebb1a1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=5be4443a22e7f8b886b867a2…
http://github.com/ceki/logback/commit/5be4443a22e7f8b886b867a29c141432179c1…
commit 5be4443a22e7f8b886b867a29c141432179c1d53
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Thu Mar 17 16:54:28 2011 +0100
working on LRUMessageCache
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
index 90cd274..cfa963f 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/LRUMessageCache.java
@@ -27,7 +27,7 @@ class LRUMessageCache extends LinkedHashMap<String, Integer> {
LRUMessageCache(int cacheSize) {
super((int) (cacheSize * (4.0f / 3)), 0.75f, true);
if (cacheSize < 1) {
- throw new IllegalArgumentException("Cache size cannnot be smaller than 1");
+ throw new IllegalArgumentException("Cache size cannot be smaller than 1");
}
this.cacheSize = cacheSize;
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
new file mode 100644
index 0000000..5e2fed3
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
@@ -0,0 +1,80 @@
+package ch.qos.logback.classic.turbo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class LRUMessageCacheTest {
+ private static final int INVOCATIONS_PER_TASK = 500 * 1024;
+ private static final int THREADS_NUMBER = 16;
+
+ @Test
+ public void testEldestEntriesRemoval() {
+ final LRUMessageCache cache = new LRUMessageCache(2);
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("0"));
+ Assert.assertEquals(1, cache.getMessageCountAndThenIncrement("0"));
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("1"));
+ Assert.assertEquals(1, cache.getMessageCountAndThenIncrement("1"));
+ // 0 entry should have been removed.
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("2"));
+ // So it is expected a returned value of 0 instead of 2.
+ // 1 entry should have been removed.
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("0"));
+ // So it is expected a returned value of 0 instead of 2.
+ // 2 entry should have been removed.
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("1"));
+ // So it is expected a returned value of 0 instead of 2.
+ Assert.assertEquals(0, cache.getMessageCountAndThenIncrement("2"));
+ }
+
+ @Test
+ public void multiThreadsTest() throws InterruptedException, ExecutionException {
+ final LRUMessageCache cache = new LRUMessageCache(THREADS_NUMBER);
+
+ ArrayList<TestTask> tasks = new ArrayList<TestTask>(THREADS_NUMBER);
+ for (int i = 0; i < THREADS_NUMBER; i++) {
+ tasks.add(new TestTask(cache));
+ }
+
+ ExecutorService execSrv = Executors.newFixedThreadPool(THREADS_NUMBER);
+
+ List<Future<Boolean>> futures = execSrv.invokeAll(tasks);
+ for (Future<Boolean> future : futures) {
+ // Validate that task has successfully finished.
+ future.get();
+ }
+ }
+
+ /**
+ * Each thread is using always the same "Message" key.
+ */
+ private class TestTask implements Callable<Boolean> {
+ private int prevValue = -1;
+ private final LRUMessageCache cache;
+
+ public TestTask(LRUMessageCache cache) {
+ this.cache = cache;
+ }
+
+ public Boolean call() throws Exception {
+ String msg = Thread.currentThread().getName();
+
+ for (int i = 0; i < INVOCATIONS_PER_TASK; i++) {
+ int current = cache.getMessageCountAndThenIncrement(msg);
+ // Ensure that new count is greater than previous count.
+ Assert.assertEquals(prevValue + 1, current);
+ prevValue = current;
+ }
+
+ return true;
+ }
+ }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/Event.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Event.java
similarity index 90%
rename from logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/Event.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Event.java
index 6219c35..b9bb777 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/Event.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Event.java
@@ -1,33 +1,33 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern.lru;
-
-public class Event<K> {
-
- final public boolean put;
- final public K k;
-
- public Event(boolean put, K k) {
- this.put = put;
- this.k = k;
- }
-
- public String toString() {
- if(put) {
- return "Event: put, "+k;
- } else {
- return "Event: get, "+k;
- }
- }
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+public class Event<K> {
+
+ final public boolean put;
+ final public K k;
+
+ public Event(boolean put, K k) {
+ this.put = put;
+ this.k = k;
+ }
+
+ public String toString() {
+ if(put) {
+ return "Event: put, "+k;
+ } else {
+ return "Event: get, "+k;
+ }
+ }
+}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LRUCache.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCache.java
similarity index 93%
rename from logback-classic/src/main/java/ch/qos/logback/classic/pattern/LRUCache.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCache.java
index c2b426a..9bec9d8 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LRUCache.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCache.java
@@ -1,51 +1,51 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * An lru cache based on Java's LinkedHashMap.
- *
- * @author Ceki Gulcu
- *
- * @param <K>
- * @param <V>
- */
-public class LRUCache<K, V> extends LinkedHashMap<K, V> {
- private static final long serialVersionUID = -6592964689843698200L;
-
- final int cacheSize;
-
- public LRUCache(int cacheSize) {
- super((int) (cacheSize*(4.0f/3)), 0.75f, true);
- if(cacheSize < 1) {
- throw new IllegalArgumentException("Cache size cannnot be smaller than 1");
- }
- this.cacheSize = cacheSize;
- }
-
- protected boolean removeEldestEntry(Map.Entry eldest) {
- return (size() > cacheSize);
- }
-
- List<K> keyList() {
- ArrayList<K> al = new ArrayList<K>();
- al.addAll(keySet());
- return al;
- }
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An lru cache based on Java's LinkedHashMap.
+ *
+ * @author Ceki Gulcu
+ *
+ * @param <K>
+ * @param <V>
+ */
+public class LRUCache<K, V> extends LinkedHashMap<K, V> {
+ private static final long serialVersionUID = -6592964689843698200L;
+
+ final int cacheSize;
+
+ public LRUCache(int cacheSize) {
+ super((int) (cacheSize*(4.0f/3)), 0.75f, true);
+ if(cacheSize < 1) {
+ throw new IllegalArgumentException("Cache size cannnot be smaller than 1");
+ }
+ this.cacheSize = cacheSize;
+ }
+
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return (size() > cacheSize);
+ }
+
+ List<K> keyList() {
+ ArrayList<K> al = new ArrayList<K>();
+ al.addAll(keySet());
+ return al;
+ }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/LRUCacheTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCacheTest.java
similarity index 95%
rename from logback-classic/src/test/java/ch/qos/logback/classic/pattern/LRUCacheTest.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCacheTest.java
index c9628b6..96e04c0 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/LRUCacheTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/LRUCacheTest.java
@@ -1,125 +1,122 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import ch.qos.logback.classic.pattern.lru.Event;
-import ch.qos.logback.classic.pattern.lru.T_LRUCache;
-
-@Ignore
-public class LRUCacheTest {
-
- @Test
- public void smoke() {
-
- LRUCache<String, String> cache = new LRUCache<String, String>(2);
- cache.put("a", "a");
- cache.put("b", "b");
- cache.put("c", "c");
- List<String> witness = new LinkedList<String>();
- witness.add("b");
- witness.add("c");
- assertEquals(witness, cache.keyList());
- }
-
- @Test
- public void typicalScenarioTest() {
- int simulationLen = 1000 * 10;
- int cacheSize = 100;
- int worldSize = 1000;
- doScenario(simulationLen, cacheSize, worldSize);
- }
-
- @Test
- public void scenarioCoverageTest() {
- int simulationLen = 1000 * 10;
-
- int[] cacheSizes = new int[] { 1, 10, 100};
- // tests with large worldSizes are slow because with a large
- // world size the probability of a cache miss is high.
- int[] worldSizes = new int[] { 1, 10, 100 };
-
- for (int i = 0; i < cacheSizes.length; i++) {
- for (int j = 0; j < worldSizes.length; j++) {
- doScenario(simulationLen, cacheSizes[i], worldSizes[j]);
- }
- }
- }
-
- void doScenario(int simulationLen, int cacheSize, int worldSize) {
- int get2PutRatio = 10;
- Simulator simulator = new Simulator(worldSize, get2PutRatio, false);
- List<Event> scenario = simulator.generateScenario(simulationLen);
- LRUCache<String, String> lruCache = new LRUCache<String, String>(cacheSize);
- T_LRUCache<String> tlruCache = new T_LRUCache<String>(cacheSize);
- long start = System.nanoTime();
- simulator.simulate(scenario, lruCache, tlruCache);
- //assertEquals(tlruCache.keyList(), lruCache.keyList());
- long end = System.nanoTime();
- System.out.println("cacheSize=" + cacheSize + ", worldSize=" + worldSize
- + ", elapsed time=" + ((end - start) / (1000 * 1000)) + " in millis");
- }
-
-
-
- @Test
- @Ignore // slow test that is known to pass
- public void multiThreadedScenario() throws InterruptedException {
- int cacheSize = 100;
- int worldSize = cacheSize*2;
- LRUCache<String, String> lruCache = new LRUCache<String, String>(cacheSize);
- T_LRUCache<String> tlruCache = new T_LRUCache<String>(cacheSize);
- SimulatorRunnable[] simulatorArray = new SimulatorRunnable[5];
- for(int i = 0; i < simulatorArray.length; i++) {
- simulatorArray[i] = new SimulatorRunnable(lruCache, tlruCache, worldSize);
- }
- for(int i = 0; i < simulatorArray.length; i++) {
- simulatorArray[i].start();
- }
- for(int i = 0; i < simulatorArray.length; i++) {
- simulatorArray[i].join();
- }
- assertEquals(tlruCache.keyList(), lruCache.keyList());
- }
-
- private class SimulatorRunnable extends Thread {
-
- LRUCache<String, String> lruCache;
- T_LRUCache<String> tlruCache;
- int worldSize;
-
- SimulatorRunnable(LRUCache<String, String> lruCache, T_LRUCache<String> tlruCache, int worldSize) {
- this.lruCache = lruCache;
- this.tlruCache = tlruCache;
- this.worldSize = worldSize;
- }
-
- public void run() {
- int get2PutRatio = 10;
- int simulationLen = 1000*50;
- Simulator simulator = new Simulator(worldSize, get2PutRatio, true);
- List<Event> scenario = simulator.generateScenario(simulationLen);
- simulator.simulate(scenario, lruCache, tlruCache);
- System.out.println("done");
- }
- }
-
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore
+public class LRUCacheTest {
+
+ @Test
+ public void smoke() {
+
+ LRUCache<String, String> cache = new LRUCache<String, String>(2);
+ cache.put("a", "a");
+ cache.put("b", "b");
+ cache.put("c", "c");
+ List<String> witness = new LinkedList<String>();
+ witness.add("b");
+ witness.add("c");
+ assertEquals(witness, cache.keyList());
+ }
+
+ @Test
+ public void typicalScenarioTest() {
+ int simulationLen = 1000 * 10;
+ int cacheSize = 100;
+ int worldSize = 1000;
+ doScenario(simulationLen, cacheSize, worldSize);
+ }
+
+ @Test
+ public void scenarioCoverageTest() {
+ int simulationLen = 1000 * 10;
+
+ int[] cacheSizes = new int[] { 1, 10, 100};
+ // tests with large worldSizes are slow because with a large
+ // world size the probability of a cache miss is high.
+ int[] worldSizes = new int[] { 1, 10, 100 };
+
+ for (int i = 0; i < cacheSizes.length; i++) {
+ for (int j = 0; j < worldSizes.length; j++) {
+ doScenario(simulationLen, cacheSizes[i], worldSizes[j]);
+ }
+ }
+ }
+
+ void doScenario(int simulationLen, int cacheSize, int worldSize) {
+ int get2PutRatio = 10;
+ Simulator simulator = new Simulator(worldSize, get2PutRatio, false);
+ List<Event> scenario = simulator.generateScenario(simulationLen);
+ LRUCache<String, String> lruCache = new LRUCache<String, String>(cacheSize);
+ T_LRUCache<String> tlruCache = new T_LRUCache<String>(cacheSize);
+ long start = System.nanoTime();
+ simulator.simulate(scenario, lruCache, tlruCache);
+ //assertEquals(tlruCache.keyList(), lruCache.keyList());
+ long end = System.nanoTime();
+ System.out.println("cacheSize=" + cacheSize + ", worldSize=" + worldSize
+ + ", elapsed time=" + ((end - start) / (1000 * 1000)) + " in millis");
+ }
+
+
+
+ @Test
+ @Ignore // slow test that is known to pass
+ public void multiThreadedScenario() throws InterruptedException {
+ int cacheSize = 100;
+ int worldSize = cacheSize*2;
+ LRUCache<String, String> lruCache = new LRUCache<String, String>(cacheSize);
+ T_LRUCache<String> tlruCache = new T_LRUCache<String>(cacheSize);
+ SimulatorRunnable[] simulatorArray = new SimulatorRunnable[5];
+ for(int i = 0; i < simulatorArray.length; i++) {
+ simulatorArray[i] = new SimulatorRunnable(lruCache, tlruCache, worldSize);
+ }
+ for(int i = 0; i < simulatorArray.length; i++) {
+ simulatorArray[i].start();
+ }
+ for(int i = 0; i < simulatorArray.length; i++) {
+ simulatorArray[i].join();
+ }
+ assertEquals(tlruCache.keyList(), lruCache.keyList());
+ }
+
+ private class SimulatorRunnable extends Thread {
+
+ LRUCache<String, String> lruCache;
+ T_LRUCache<String> tlruCache;
+ int worldSize;
+
+ SimulatorRunnable(LRUCache<String, String> lruCache, T_LRUCache<String> tlruCache, int worldSize) {
+ this.lruCache = lruCache;
+ this.tlruCache = tlruCache;
+ this.worldSize = worldSize;
+ }
+
+ public void run() {
+ int get2PutRatio = 10;
+ int simulationLen = 1000*50;
+ Simulator simulator = new Simulator(worldSize, get2PutRatio, true);
+ List<Event> scenario = simulator.generateScenario(simulationLen);
+ simulator.simulate(scenario, lruCache, tlruCache);
+ System.out.println("done");
+ }
+ }
+
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/Simulator.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Simulator.java
similarity index 94%
rename from logback-classic/src/test/java/ch/qos/logback/classic/pattern/Simulator.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Simulator.java
index d07fdc4..a1eea56 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/Simulator.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/Simulator.java
@@ -1,92 +1,89 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-import ch.qos.logback.classic.pattern.lru.Event;
-import ch.qos.logback.classic.pattern.lru.T_LRUCache;
-
-public class Simulator {
-
- Random random;
-
- int worldSize;
- int get2PutRatio;
- boolean multiThreaded;
-
- public Simulator(int worldSize, int get2PutRatio, boolean multiThreaded) {
- this.worldSize = worldSize;
- this.get2PutRatio = get2PutRatio;
- long seed = System.nanoTime();
- // System.out.println("seed is "+seed);
- random = new Random(seed);
- this.multiThreaded = multiThreaded;
- }
-
- public List<Event> generateScenario(int len) {
- List<Event> scenario = new ArrayList<Event>();
-
- for (int i = 0; i < len; i++) {
-
- int r = random.nextInt(get2PutRatio);
- boolean put = false;
- if (r == 0) {
- put = true;
- }
- r = random.nextInt(worldSize);
- Event<String> e = new Event<String>(put, String.valueOf(r));
- scenario.add(e);
- }
- return scenario;
- }
-
- public void simulate(List<Event> scenario, LRUCache<String, String> lruCache,
- T_LRUCache<String> tlruCache) {
- for (Event<String> e : scenario) {
- if (e.put) {
- lruCache.put(e.k, e.k);
- tlruCache.put(e.k);
- } else {
- String r0 = lruCache.get(e.k);
- String r1 = tlruCache.get(e.k);
- if (!multiThreaded) {
- // if the simulation is used in a multi-threaded
- // context, then the state of lruCache may be different than
- // that of tlruCache. In single threaded mode, they should
- // return the same values all the time
- if (r0 != null) {
- assertEquals(r0, e.k);
- }
- assertEquals(r0, r1);
- }
- }
- }
- }
-
- // void compareAndDumpIfDifferent(LRUCache<String, String> lruCache,
- // T_LRUCache<String> tlruCache) {
- // lruCache.dump();
- // tlruCache.dump();
- // if(!lruCache.keyList().equals(tlruCache.ketList())) {
- // lruCache.dump();
- // tlruCache.dump();
- // throw new AssertionFailedError("s");
- // }
- // }
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class Simulator {
+
+ Random random;
+
+ int worldSize;
+ int get2PutRatio;
+ boolean multiThreaded;
+
+ public Simulator(int worldSize, int get2PutRatio, boolean multiThreaded) {
+ this.worldSize = worldSize;
+ this.get2PutRatio = get2PutRatio;
+ long seed = System.nanoTime();
+ // System.out.println("seed is "+seed);
+ random = new Random(seed);
+ this.multiThreaded = multiThreaded;
+ }
+
+ public List<Event> generateScenario(int len) {
+ List<Event> scenario = new ArrayList<Event>();
+
+ for (int i = 0; i < len; i++) {
+
+ int r = random.nextInt(get2PutRatio);
+ boolean put = false;
+ if (r == 0) {
+ put = true;
+ }
+ r = random.nextInt(worldSize);
+ Event<String> e = new Event<String>(put, String.valueOf(r));
+ scenario.add(e);
+ }
+ return scenario;
+ }
+
+ public void simulate(List<Event> scenario, LRUCache<String, String> lruCache,
+ T_LRUCache<String> tlruCache) {
+ for (Event<String> e : scenario) {
+ if (e.put) {
+ lruCache.put(e.k, e.k);
+ tlruCache.put(e.k);
+ } else {
+ String r0 = lruCache.get(e.k);
+ String r1 = tlruCache.get(e.k);
+ if (!multiThreaded) {
+ // if the simulation is used in a multi-threaded
+ // context, then the state of lruCache may be different than
+ // that of tlruCache. In single threaded mode, they should
+ // return the same values all the time
+ if (r0 != null) {
+ assertEquals(r0, e.k);
+ }
+ assertEquals(r0, r1);
+ }
+ }
+ }
+ }
+
+ // void compareAndDumpIfDifferent(LRUCache<String, String> lruCache,
+ // T_LRUCache<String> tlruCache) {
+ // lruCache.dump();
+ // tlruCache.dump();
+ // if(!lruCache.keyList().equals(tlruCache.ketList())) {
+ // lruCache.dump();
+ // tlruCache.dump();
+ // throw new AssertionFailedError("s");
+ // }
+ // }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_Entry.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
similarity index 92%
rename from logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_Entry.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
index 59cff0a..980ab2e 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_Entry.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_Entry.java
@@ -1,45 +1,45 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern.lru;
-
-public class T_Entry<K> implements Comparable {
-
- K k;
- long sequenceNumber;
-
- T_Entry(K k, long sn) {
- this.k = k;
- this.sequenceNumber = sn;
- }
-
- public int compareTo(Object o) {
- if(!(o instanceof T_Entry)) {
- throw new IllegalArgumentException("arguments must be of type "+T_Entry.class);
- }
-
- T_Entry other = (T_Entry) o;
- if(sequenceNumber > other.sequenceNumber) {
- return 1;
- }
- if(sequenceNumber == other.sequenceNumber) {
- return 0;
- }
- return -1;
- }
- @Override
- public String toString() {
- return "("+k+","+sequenceNumber+")";
- //return "("+k+")";
- }
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+public class T_Entry<K> implements Comparable {
+
+ K k;
+ long sequenceNumber;
+
+ T_Entry(K k, long sn) {
+ this.k = k;
+ this.sequenceNumber = sn;
+ }
+
+ public int compareTo(Object o) {
+ if(!(o instanceof T_Entry)) {
+ throw new IllegalArgumentException("arguments must be of type "+T_Entry.class);
+ }
+
+ T_Entry other = (T_Entry) o;
+ if(sequenceNumber > other.sequenceNumber) {
+ return 1;
+ }
+ if(sequenceNumber == other.sequenceNumber) {
+ return 0;
+ }
+ return -1;
+ }
+ @Override
+ public String toString() {
+ return "("+k+","+sequenceNumber+")";
+ //return "("+k+")";
+ }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_LRUCache.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
similarity index 94%
rename from logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_LRUCache.java
rename to logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
index d132ee1..ebb7150 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/pattern/lru/T_LRUCache.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/lru/T_LRUCache.java
@@ -1,93 +1,93 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, 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.pattern.lru;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * This is an alternative (slower) implementation of LRUCache for testing
- * purposes.
- *
- * @author Ceki Gulcu
- */
-public class T_LRUCache<K> {
-
- int sequenceNumber;
- final int cacheSize;
- List<T_Entry<K>> cacheList = new LinkedList<T_Entry<K>>();
-
- public T_LRUCache(int size) {
- this.cacheSize = size;
- }
-
- @SuppressWarnings("unchecked")
- synchronized public void put(K k) {
- sequenceNumber++;
- T_Entry<K> te = getEntry(k);
- if (te != null) {
- te.sequenceNumber = sequenceNumber;
- } else {
- te = new T_Entry<K>(k, sequenceNumber);
- cacheList.add(te);
- }
- Collections.sort(cacheList);
- while(cacheList.size() > cacheSize) {
- cacheList.remove(0);
- }
- }
-
- @SuppressWarnings("unchecked")
- synchronized public K get(K k) {
- T_Entry<K> te = getEntry(k);
- if (te == null) {
- return null;
- } else {
- te.sequenceNumber = ++sequenceNumber;
- Collections.sort(cacheList);
- return te.k;
- }
- }
-
- synchronized public List<K> keyList() {
- List<K> keyList = new ArrayList<K>();
- for (T_Entry<K> e : cacheList) {
- keyList.add(e.k);
- }
- return keyList;
- }
-
- private T_Entry<K> getEntry(K k) {
- for (int i = 0; i < cacheList.size(); i++) {
- T_Entry<K> te = cacheList.get(i);
- if (te.k.equals(k)) {
- return te;
- }
- }
- return null;
- }
-
- public void dump() {
- System.out.print("T:");
- for (T_Entry<K> te : cacheList) {
- //System.out.print(te.toString()+"->");
- System.out.print(te.k+", ");
- }
- System.out.println();
- }
-
-}
-
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, 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.turbo.lru;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * This is an alternative (slower) implementation of LRUCache for testing
+ * purposes.
+ *
+ * @author Ceki Gulcu
+ */
+public class T_LRUCache<K> {
+
+ int sequenceNumber;
+ final int cacheSize;
+ List<T_Entry<K>> cacheList = new LinkedList<T_Entry<K>>();
+
+ public T_LRUCache(int size) {
+ this.cacheSize = size;
+ }
+
+ @SuppressWarnings("unchecked")
+ synchronized public void put(K k) {
+ sequenceNumber++;
+ T_Entry<K> te = getEntry(k);
+ if (te != null) {
+ te.sequenceNumber = sequenceNumber;
+ } else {
+ te = new T_Entry<K>(k, sequenceNumber);
+ cacheList.add(te);
+ }
+ Collections.sort(cacheList);
+ while(cacheList.size() > cacheSize) {
+ cacheList.remove(0);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ synchronized public K get(K k) {
+ T_Entry<K> te = getEntry(k);
+ if (te == null) {
+ return null;
+ } else {
+ te.sequenceNumber = ++sequenceNumber;
+ Collections.sort(cacheList);
+ return te.k;
+ }
+ }
+
+ synchronized public List<K> keyList() {
+ List<K> keyList = new ArrayList<K>();
+ for (T_Entry<K> e : cacheList) {
+ keyList.add(e.k);
+ }
+ return keyList;
+ }
+
+ private T_Entry<K> getEntry(K k) {
+ for (int i = 0; i < cacheList.size(); i++) {
+ T_Entry<K> te = cacheList.get(i);
+ if (te.k.equals(k)) {
+ return te;
+ }
+ }
+ return null;
+ }
+
+ public void dump() {
+ System.out.print("T:");
+ for (T_Entry<K> te : cacheList) {
+ //System.out.print(te.toString()+"->");
+ System.out.print(te.k+", ");
+ }
+ System.out.println();
+ }
+
+}
+
-----------------------------------------------------------------------
Summary of changes:
.../qos/logback/classic/turbo/LRUMessageCache.java | 2 +-
.../logback/classic/turbo/LRUMessageCacheTest.java | 80 +++++++
.../classic/{pattern => turbo}/lru/Event.java | 66 +++---
.../qos/logback/classic/turbo/lru}/LRUCache.java | 102 ++++----
.../{pattern => turbo/lru}/LRUCacheTest.java | 247 ++++++++++----------
.../classic/{pattern => turbo/lru}/Simulator.java | 181 +++++++--------
.../classic/{pattern => turbo}/lru/T_Entry.java | 90 ++++----
.../classic/{pattern => turbo}/lru/T_LRUCache.java | 186 ++++++++--------
8 files changed, 514 insertions(+), 440 deletions(-)
create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/turbo/LRUMessageCacheTest.java
rename logback-classic/src/test/java/ch/qos/logback/classic/{pattern => turbo}/lru/Event.java (90%)
rename logback-classic/src/{main/java/ch/qos/logback/classic/pattern => test/java/ch/qos/logback/classic/turbo/lru}/LRUCache.java (93%)
rename logback-classic/src/test/java/ch/qos/logback/classic/{pattern => turbo/lru}/LRUCacheTest.java (95%)
rename logback-classic/src/test/java/ch/qos/logback/classic/{pattern => turbo/lru}/Simulator.java (94%)
rename logback-classic/src/test/java/ch/qos/logback/classic/{pattern => turbo}/lru/T_Entry.java (92%)
rename logback-classic/src/test/java/ch/qos/logback/classic/{pattern => turbo}/lru/T_LRUCache.java (94%)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-25-gd88160e
by git-noreply@pixie.qos.ch 15 Mar '11
by git-noreply@pixie.qos.ch 15 Mar '11
15 Mar '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via d88160e448083dcf5524bf926b45b91cf4ebb1a1 (commit)
from f23196e82fa25ef60ea80ad0470e6dd074cdc3ae (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=d88160e448083dcf5524bf92…
http://github.com/ceki/logback/commit/d88160e448083dcf5524bf926b45b91cf4ebb…
commit d88160e448083dcf5524bf926b45b91cf4ebb1a1
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Tue Mar 15 18:41:26 2011 +0100
dabbling in yoda time
diff --git a/logback-core/pom.xml b/logback-core/pom.xml
index 51bb098..03383ed 100644
--- a/logback-core/pom.xml
+++ b/logback-core/pom.xml
@@ -84,6 +84,13 @@
<artifactId>scala-library</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <optional>true</optional>
+ </dependency>
+
</dependencies>
diff --git a/logback-core/src/test/java/ch/qos/logback/core/time/DateFormattingThroughputTest.java b/logback-core/src/test/java/ch/qos/logback/core/time/DateFormattingThroughputTest.java
new file mode 100644
index 0000000..624390d
--- /dev/null
+++ b/logback-core/src/test/java/ch/qos/logback/core/time/DateFormattingThroughputTest.java
@@ -0,0 +1,99 @@
+package ch.qos.logback.core.time;
+
+import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
+import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+
+@Ignore
+public class DateFormattingThroughputTest {
+
+
+ ThreadedThroughputCalculator t;
+
+ static int THREAD_COUNT = 30;
+ static long OVERALL_DURATION_IN_MILLIS = 2000;
+
+ static String PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
+
+ @Test
+ public void sdf() throws InterruptedException {
+ ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(
+ OVERALL_DURATION_IN_MILLIS);
+
+ SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
+ RunnableWithCounterAndDone[] sdfRunnables = buildSDFRunnables(sdf);
+ tp.execute(sdfRunnables);
+ tp.printThroughput("SDF with synchronization: ", true);
+ }
+
+ RunnableWithCounterAndDone[] buildSDFRunnables(SimpleDateFormat sdf) {
+ RunnableWithCounterAndDone[] runnables = new RunnableWithCounterAndDone[THREAD_COUNT];
+ for (int i = 0; i < THREAD_COUNT; i++) {
+ runnables[i] = new SDFRunnabable(sdf);
+ }
+ return runnables;
+ }
+
+ @Test
+ public void yoda() throws InterruptedException {
+ ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(
+ OVERALL_DURATION_IN_MILLIS);
+
+ DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN);
+ RunnableWithCounterAndDone[] yodaRunnables = buildYodaRunnables(fmt);
+ tp.execute(yodaRunnables);
+ tp.printThroughput("Yoda: ", true);
+ }
+
+ RunnableWithCounterAndDone[] buildYodaRunnables(DateTimeFormatter fmt) {
+ RunnableWithCounterAndDone[] runnables = new RunnableWithCounterAndDone[THREAD_COUNT];
+ for (int i = 0; i < THREAD_COUNT; i++) {
+ runnables[i] = new YodaTimeRunnable(fmt);
+ }
+ return runnables;
+ }
+
+
+ class SDFRunnabable extends RunnableWithCounterAndDone {
+
+ SimpleDateFormat sdf;
+
+ SDFRunnabable(SimpleDateFormat sdf) {
+ this.sdf = sdf;
+ }
+
+ public void run() {
+ while (!done) {
+ synchronized (sdf) {
+ sdf.format(new Date());
+ }
+ counter++;
+ }
+ }
+ }
+
+ class YodaTimeRunnable extends RunnableWithCounterAndDone {
+
+ DateTimeFormatter yodaDTFt;
+
+ YodaTimeRunnable(DateTimeFormatter dtf) {
+ this.yodaDTFt = dtf;
+ }
+
+ public void run() {
+ while (!done) {
+ long now = System.currentTimeMillis();
+ yodaDTFt.print(now);
+ counter++;
+ }
+ }
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 514ea01..6a30698 100755
--- a/pom.xml
+++ b/pom.xml
@@ -167,6 +167,12 @@
<version>${scala.version}</version>
</dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
-----------------------------------------------------------------------
Summary of changes:
logback-core/pom.xml | 7 ++
.../core/time/DateFormattingThroughputTest.java | 99 ++++++++++++++++++++
pom.xml | 6 +
3 files changed, 112 insertions(+), 0 deletions(-)
create mode 100644 logback-core/src/test/java/ch/qos/logback/core/time/DateFormattingThroughputTest.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0

[JIRA] Created: (LBSITE-44) Type-o on Layouts Page in Conversion
by Gordon Dickens (JIRA) 11 Mar '11
by Gordon Dickens (JIRA) 11 Mar '11
11 Mar '11
Type-o on Layouts Page in Conversion
------------------------------------
Key: LBSITE-44
URL: http://jira.qos.ch/browse/LBSITE-44
Project: logback-site
Issue Type: Bug
Components: Documentation
Affects Versions: 0.9.29
Reporter: Gordon Dickens
Assignee: Logback dev list
Layouts conversion page specifies the highest level as "26", should this be 36"?
http://logback.qos.ch/manual/layouts.html
Regards,
Gordon Dickens
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
2
4

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-24-gf23196e
by git-noreply@pixie.qos.ch 11 Mar '11
by git-noreply@pixie.qos.ch 11 Mar '11
11 Mar '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via f23196e82fa25ef60ea80ad0470e6dd074cdc3ae (commit)
from a7582c96029b7666fb2a0380dd8a60af2cce613c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=f23196e82fa25ef60ea80ad0…
http://github.com/ceki/logback/commit/f23196e82fa25ef60ea80ad0470e6dd074cdc…
commit f23196e82fa25ef60ea80ad0470e6dd074cdc3ae
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Fri Mar 11 19:01:25 2011 +0100
fixing LBCORE-199
diff --git a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
index 0989645..c58081e 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
@@ -35,6 +35,7 @@ public class CoreConstants {
public static final String ISO8601_STR = "ISO8601";
public static final String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";
+ public static final String DAILY_DATE_PATTERN = "yyyy-MM-dd";
/**
* Time format used in Common Log Format
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
index 556f45e..7cb9a09 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
@@ -14,12 +14,10 @@
package ch.qos.logback.core.rolling;
import java.io.File;
+import java.util.Date;
import ch.qos.logback.core.CoreConstants;
-import ch.qos.logback.core.rolling.helper.Compressor;
-import ch.qos.logback.core.rolling.helper.FileNamePattern;
-import ch.qos.logback.core.rolling.helper.IntegerTokenConverter;
-import ch.qos.logback.core.rolling.helper.RenameUtil;
+import ch.qos.logback.core.rolling.helper.*;
/**
* When rolling over, <code>FixedWindowRollingPolicy</code> renames files
@@ -38,7 +36,7 @@ public class FixedWindowRollingPolicy extends RollingPolicyBase {
int minIndex;
RenameUtil util = new RenameUtil();
Compressor compressor;
-
+
/**
* It's almost always a bad idea to have a large window size, say over 12.
*/
@@ -94,11 +92,21 @@ public class FixedWindowRollingPolicy extends RollingPolicyBase {
+ "] does not contain a valid IntegerToken");
}
+ if(compressionMode == CompressionMode.ZIP) {
+ String zipEntryFileNamePatternStr = transformFileNamePatternFromInt2Date(fileNamePatternStr);
+ zipEntryFileNamePattern = new FileNamePattern(zipEntryFileNamePatternStr, context);
+ }
compressor = new Compressor(compressionMode);
compressor.setContext(this.context);
super.start();
}
+ private String transformFileNamePatternFromInt2Date(String fileNamePatternStr) {
+ String slashified = FileFilterUtil.slashify(fileNamePatternStr);
+ String stemOfFileNamePattern = FileFilterUtil.afterLastSlash(slashified);
+ return stemOfFileNamePattern.replace("%i", "%d");
+ }
+
public void rollover() throws RolloverFailure {
// Inside this method it is guaranteed that the hereto active log file is
@@ -131,17 +139,17 @@ public class FixedWindowRollingPolicy extends RollingPolicyBase {
.convertInt(minIndex));
break;
case GZ:
+ compressor.compress(getActiveFileName(), fileNamePattern.convertInt(minIndex), null);
+ break;
case ZIP:
- compressor.compress(getActiveFileName(), fileNamePattern.convertInt(minIndex));
+ compressor.compress(getActiveFileName(), fileNamePattern.convertInt(minIndex), zipEntryFileNamePattern.convert(new Date()));
break;
}
}
}
/**
- * Return the value of the <b>ActiveFile</b> option.
- *
- * @see {@link setActiveFileName}.
+ * Return the value of the parent's RawFile property.
*/
public String getActiveFileName() {
return getParentsRawFileProperty();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
index 5f47444..df69816 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
@@ -33,6 +33,8 @@ public abstract class RollingPolicyBase extends ContextAwareBase implements
private FileAppender parent;
+ // use to name files within zip file, i.e. the zipEntry
+ FileNamePattern zipEntryFileNamePattern;
private boolean started;
/**
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
index 5328db7..91f67fa 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
@@ -86,10 +86,6 @@ abstract public class TimeBasedFileNamingAndTriggeringPolicyBase<E> extends
this.dateInCurrentPeriod = _dateInCurrentPeriod;
}
- public Date getDateInCurrentPeriod() {
- return dateInCurrentPeriod;
- }
-
public String getElapsedPeriodsFileName() {
return elapsedPeriodsFileName;
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
index 1159aa5..8ebe445 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
@@ -18,12 +18,8 @@ import java.util.Date;
import java.util.concurrent.Future;
import ch.qos.logback.core.CoreConstants;
-import ch.qos.logback.core.rolling.helper.ArchiveRemover;
-import ch.qos.logback.core.rolling.helper.AsynchronousCompressor;
-import ch.qos.logback.core.rolling.helper.CompressionMode;
-import ch.qos.logback.core.rolling.helper.Compressor;
-import ch.qos.logback.core.rolling.helper.FileNamePattern;
-import ch.qos.logback.core.rolling.helper.RenameUtil;
+import ch.qos.logback.core.rolling.helper.*;
+import ch.qos.logback.core.util.FileUtil;
/**
* <code>TimeBasedRollingPolicy</code> is both easy to configure and quite
@@ -77,6 +73,11 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
addInfo("Will use the pattern " + fileNamePatternWCS
+ " for the active file");
+ if(compressionMode == CompressionMode.ZIP) {
+ String zipEntryFileNamePatternStr = transformFileNamePattern2ZipEntry(fileNamePatternStr);
+ zipEntryFileNamePattern = new FileNamePattern(zipEntryFileNamePatternStr, context);
+ }
+
if (timeBasedFileNamingAndTriggeringPolicy == null) {
timeBasedFileNamingAndTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
}
@@ -95,6 +96,11 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
super.start();
}
+ private String transformFileNamePattern2ZipEntry(String fileNamePatternStr) {
+ String slashified = FileFilterUtil.slashify(fileNamePatternStr);
+ return FileFilterUtil.afterLastSlash(slashified);
+ }
+
public void setTimeBasedFileNamingAndTriggeringPolicy(
TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
this.timeBasedFileNamingAndTriggeringPolicy = timeBasedTriggering;
@@ -112,15 +118,18 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
String elapsedPeriodsFileName = timeBasedFileNamingAndTriggeringPolicy
.getElapsedPeriodsFileName();
+ String elpasedPeriodStem = FileFilterUtil.afterLastSlash(elapsedPeriodsFileName);
+
+
if (compressionMode == CompressionMode.NONE) {
if (getParentsRawFileProperty() != null) {
renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);
} // else { nothing to do if CompressionMode == NONE and parentsRawFileProperty == null }
} else {
if (getParentsRawFileProperty() == null) {
- future = asyncCompress(elapsedPeriodsFileName, elapsedPeriodsFileName);
+ future = asyncCompress(elapsedPeriodsFileName, elapsedPeriodsFileName, elpasedPeriodStem);
} else {
- future = renamedRawAndAsyncCompress(elapsedPeriodsFileName);
+ future = renamedRawAndAsyncCompress(elapsedPeriodsFileName, elpasedPeriodStem);
}
}
@@ -129,18 +138,18 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
}
}
- Future asyncCompress(String nameOfFile2Compress, String nameOfCompressedFile)
+ Future asyncCompress(String nameOfFile2Compress, String nameOfCompressedFile, String innerEntryName)
throws RolloverFailure {
AsynchronousCompressor ac = new AsynchronousCompressor(compressor);
- return ac.compressAsynchronously(nameOfFile2Compress, nameOfCompressedFile);
+ return ac.compressAsynchronously(nameOfFile2Compress, nameOfCompressedFile, innerEntryName);
}
- Future renamedRawAndAsyncCompress(String nameOfCompressedFile)
+ Future renamedRawAndAsyncCompress(String nameOfCompressedFile, String innerEntryName)
throws RolloverFailure {
String parentsRawFile = getParentsRawFileProperty();
String tmpTarget = parentsRawFile + System.nanoTime() + ".tmp";
renameUtil.rename(parentsRawFile, tmpTarget);
- return asyncCompress(tmpTarget, nameOfCompressedFile);
+ return asyncCompress(tmpTarget, nameOfCompressedFile, innerEntryName);
}
/**
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/AsynchronousCompressor.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/AsynchronousCompressor.java
index 569221a..03af6fd 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/AsynchronousCompressor.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/AsynchronousCompressor.java
@@ -25,10 +25,10 @@ public class AsynchronousCompressor {
}
public Future<?> compressAsynchronously(String nameOfFile2Compress,
- String nameOfCompressedFile) {
+ String nameOfCompressedFile, String innerEntryName) {
ExecutorService executor = Executors.newScheduledThreadPool(1);
Future<?> future = executor.submit(new CompressionRunnable(compressor,
- nameOfFile2Compress, nameOfCompressedFile));
+ nameOfFile2Compress, nameOfCompressedFile, innerEntryName));
executor.shutdown();
return future;
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/CompressionRunnable.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/CompressionRunnable.java
index 425282f..8a0c54c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/CompressionRunnable.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/CompressionRunnable.java
@@ -18,16 +18,18 @@ public class CompressionRunnable implements Runnable {
final Compressor compressor;
final String nameOfFile2Compress;
- final String nameOfCompressedFile;
-
+ final String nameOfCompressedFile;
+ final String innerEntryName;
+
public CompressionRunnable(Compressor compressor, String nameOfFile2Compress,
- String nameOfCompressedFile) {
+ String nameOfCompressedFile, String innerEntryName) {
this.compressor = compressor;
this.nameOfFile2Compress = nameOfFile2Compress;
this.nameOfCompressedFile = nameOfCompressedFile;
+ this.innerEntryName = innerEntryName;
}
public void run() {
- compressor.compress(nameOfFile2Compress, nameOfCompressedFile);
+ compressor.compress(nameOfFile2Compress, nameOfCompressedFile, innerEntryName);
}
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compressor.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compressor.java
index cb2f899..2ecceb5 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compressor.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compressor.java
@@ -39,7 +39,13 @@ public class Compressor extends ContextAwareBase {
this.compressionMode = compressionMode;
}
- public void compress(String nameOfFile2Compress, String nameOfCompressedFile) {
+ /**
+ *
+ * @param nameOfFile2Compress
+ * @param nameOfCompressedFile
+ * @param innerEntryName The name of the file within the zip file. Use for ZIP compression.
+ */
+ public void compress(String nameOfFile2Compress, String nameOfCompressedFile, String innerEntryName) {
switch (compressionMode) {
case GZ:
addInfo("GZ compressing [" + nameOfFile2Compress + "].");
@@ -47,7 +53,7 @@ public class Compressor extends ContextAwareBase {
break;
case ZIP:
addInfo("ZIP compressing [" + nameOfFile2Compress + "].");
- zipCompress(nameOfFile2Compress, nameOfCompressedFile);
+ zipCompress(nameOfFile2Compress, nameOfCompressedFile, innerEntryName);
break;
case NONE:
throw new UnsupportedOperationException(
@@ -55,7 +61,7 @@ public class Compressor extends ContextAwareBase {
}
}
- private void zipCompress(String nameOfFile2zip, String nameOfZippedFile) {
+ private void zipCompress(String nameOfFile2zip, String nameOfZippedFile, String innerEntryName) {
File file2zip = new File(nameOfFile2zip);
if (!file2zip.exists()) {
@@ -65,6 +71,11 @@ public class Compressor extends ContextAwareBase {
return;
}
+ if(innerEntryName == null) {
+ addStatus(new WarnStatus("The innerEntryName parameter cannot be null", this));
+ return;
+ }
+
if (!nameOfZippedFile.endsWith(".zip")) {
nameOfZippedFile = nameOfZippedFile + ".zip";
}
@@ -83,7 +94,7 @@ public class Compressor extends ContextAwareBase {
ZipOutputStream zos = new ZipOutputStream(fos);
FileInputStream fis = new FileInputStream(nameOfFile2zip);
- ZipEntry zipEntry = computeZipEntry(zippedFile);
+ ZipEntry zipEntry = computeZipEntry(innerEntryName);
zos.putNextEntry(zipEntry);
byte[] inbuf = new byte[8102];
@@ -112,7 +123,7 @@ public class Compressor extends ContextAwareBase {
// Case 1: RawFile = null, Patern = foo-%d.zip
// nestedFilename = foo-${current-date}
//
- // Case 2: RawFile = hello.txtm, Pattern = = foo-%d.zip
+ // Case 2: RawFile = hello.txt, Pattern = = foo-%d.zip
// nestedFilename = foo-${current-date}
//
// in both cases, the strategy consisting of removing the compression
@@ -122,10 +133,15 @@ public class Compressor extends ContextAwareBase {
// all having the same name, which could make it harder for the user
// to unzip the file without collisions
ZipEntry computeZipEntry(File zippedFile) {
- String nameOfFileNestedWithinArchive = computeFileNameStr_WCS(zippedFile.getName(), compressionMode);
+ return computeZipEntry(zippedFile.getName());
+ }
+
+ ZipEntry computeZipEntry(String filename) {
+ String nameOfFileNestedWithinArchive = computeFileNameStr_WCS(filename, compressionMode);
return new ZipEntry(nameOfFileNestedWithinArchive);
}
+
private void gzCompress(String nameOfFile2gz, String nameOfgzedFile) {
File file2gz = new File(nameOfFile2gz);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
index 353e992..3c7a82d 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
@@ -16,6 +16,7 @@ package ch.qos.logback.core.rolling.helper;
import java.text.SimpleDateFormat;
import java.util.Date;
+import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.pattern.DynamicConverter;
/**
@@ -29,6 +30,7 @@ public class DateTokenConverter<E> extends DynamicConverter<E> implements MonoTy
* The conversion word/character with which this converter is registered.
*/
public final static String CONVERTER_KEY = "d";
+ public static final String DEFAULT_DATE_PATTERN = CoreConstants.DAILY_DATE_PATTERN;
private String datePattern;
private SimpleDateFormat sdf;
@@ -39,8 +41,7 @@ public class DateTokenConverter<E> extends DynamicConverter<E> implements MonoTy
public void start() {
this.datePattern = getFirstOption();
if (this.datePattern == null) {
- this.datePattern = "yyyy-MM-dd";
- ;
+ this.datePattern = DEFAULT_DATE_PATTERN;
}
sdf = new SimpleDateFormat(datePattern);
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
index 4522758..87f674b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
@@ -42,8 +42,7 @@ public class DefaultArchiveRemover extends ContextAwareBase implements
return true;
}
// if the literal string subsequent to the dtc contains a /, we also
- // need
- // parent cleaning
+ // need parent cleaning
Converter<Object> p = fileNamePattern.headTokenConverter;
@@ -88,17 +87,17 @@ public class DefaultArchiveRemover extends ContextAwareBase implements
* times.
*
* @param dir
- * @param recursivityCount
+ * @param depth
*/
- void removeFolderIfEmpty(File dir, int recursivityCount) {
+ void removeFolderIfEmpty(File dir, int depth) {
// we should never go more than 3 levels higher
- if (recursivityCount >= 3) {
+ if (depth >= 3) {
return;
}
if (dir.isDirectory() && FileFilterUtil.isEmptyDirectory(dir)) {
addInfo("deleting folder [" + dir +"]");
dir.delete();
- removeFolderIfEmpty(dir.getParentFile(), recursivityCount + 1);
+ removeFolderIfEmpty(dir.getParentFile(), depth + 1);
}
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
index 0653905..4e76249 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
@@ -16,6 +16,8 @@ package ch.qos.logback.core.rolling;
import static org.junit.Assert.fail;
import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.List;
import org.junit.After;
import org.junit.Before;
@@ -126,7 +128,7 @@ public class SizeBasedRollingTest extends ScaffoldingForRollingTests {
rfa.doAppend(prefix+i);
}
- expectedFilenameList.add(randomOutputDir + "a-sizeBased-smoke.log");
+ expectedFilenameList.add(randomOutputDir + "a-sizeBased-smoke.log");
expectedFilenameList.add(randomOutputDir + "sizeBased-smoke.0");
expectedFilenameList.add(randomOutputDir + "sizeBased-smoke.1");
existenceCheck(expectedFilenameList);
@@ -174,7 +176,60 @@ public class SizeBasedRollingTest extends ScaffoldingForRollingTests {
existenceCheck(expectedFilenameList);
reverseSortedContentCheck(randomOutputDir, runLength, prefix);
-
}
+ @Test
+ public void test3Zip() throws Exception {
+ Context context = new ContextBase();
+ RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
+ rfa.setEncoder(new EchoEncoder<Object>());
+ rfa.setContext(context);
+ rfa.setFile(randomOutputDir + "a-sbr-test3.log");
+
+ FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
+ fwrp.setContext(context);
+ SizeBasedTriggeringPolicy<Object> sbtp = new SizeBasedTriggeringPolicy<Object>();
+ sbtp.setContext(context);
+
+ sbtp.setMaxFileSize("100");
+ fwrp.setMinIndex(0);
+ // fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX +
+ // "output/sbr-test3.log");
+ fwrp.setFileNamePattern(randomOutputDir + "sbr-test3.%i.zip");
+ fwrp.setParent(rfa);
+ fwrp.start();
+ rfa.setRollingPolicy(fwrp);
+ rfa.setTriggeringPolicy(sbtp);
+ rfa.start();
+
+ int runLength = 40;
+ String prefix = "hello";
+ for (int i = 0; i < runLength; i++) {
+ Thread.sleep(10);
+ rfa.doAppend("hello"+i);
+ }
+ expectedFilenameList.add(randomOutputDir + "a-sbr-test3.log");
+ expectedFilenameList.add(randomOutputDir + "sbr-test3.0.zip");
+ expectedFilenameList.add(randomOutputDir + "sbr-test3.1.zip");
+
+ existenceCheck(expectedFilenameList);
+ reverseSortedContentCheck(randomOutputDir, runLength, prefix);
+ zipEntryNameCheck(expectedFilenameList);
+ //fail("we should check zipEntries names as well");
+
+ }
+
+ private void zipEntryNameCheck(List<String> expectedFilenameList) {
+ for(String filepath: expectedFilenameList) {
+ if(filepath.endsWith(".zip")) {
+ checkZipEntyName(filepath, "sbr-test3.%i.zip");
+ }
+ }
+ }
+
+ SimpleDateFormat SDF = new SimpleDateFormat();
+ private void checkZipEntyName(String filepath, String pattern) {
+ fail("to be continued");
+
+ }
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
index 759a2fa..e3f5ac1 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
@@ -29,6 +29,8 @@ import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.util.StatusPrinter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -47,7 +49,6 @@ public class TimeBasedRollingWithArchiveRemovalTest {
static final String MONTHLY_DATE_PATTERN = "yyyy-MM";
static final String MONTHLY_CROLOLOG_DATE_PATTERN = "yyyy/MM";
- static final String DAILY_DATE_PATTERN = "yyyy-MM-dd";
static final String DAILY_CROLOLOG_DATE_PATTERN = "yyyy/MM/dd";
static final long MILLIS_IN_MINUTE = 60 * 1000;
@@ -112,14 +113,15 @@ public class TimeBasedRollingWithArchiveRemovalTest {
+ "}/clean.txt.zip", MILLIS_IN_MONTH, maxHistory, numPeriods);
int beginPeriod = Calendar.getInstance().get(Calendar.MONTH);
boolean extraFolder = extraFolder(numPeriods, 12, beginPeriod, maxHistory);
+ StatusPrinter.print(context);
check(expectedCountWithFolders(2, extraFolder));
}
@Test
public void dailyRollover() throws Exception {
- slashCount = computeSlashCount(DAILY_DATE_PATTERN);
+ slashCount = computeSlashCount(CoreConstants.DAILY_DATE_PATTERN);
doRollover(
- randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip",
+ randomOutputDir + "clean-%d{" + CoreConstants.DAILY_DATE_PATTERN + "}.txt.zip",
MILLIS_IN_DAY, 5, 5 * 3);
check(expectedCountWithoutFolders(5));
}
@@ -142,9 +144,9 @@ public class TimeBasedRollingWithArchiveRemovalTest {
sizeAndTimeBasedFNATP.setMaxFileSize("10000");
tbfnatp = sizeAndTimeBasedFNATP;
- slashCount = computeSlashCount(DAILY_DATE_PATTERN);
+ slashCount = computeSlashCount(CoreConstants.DAILY_DATE_PATTERN);
doRollover(
- randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip",
+ randomOutputDir + "/%d{" + CoreConstants.DAILY_DATE_PATTERN + "}-clean.%i.zip",
MILLIS_IN_DAY, 5, 5 * 4);
// make .zip optional so that if for one reason or another, no size-based
@@ -163,7 +165,7 @@ public class TimeBasedRollingWithArchiveRemovalTest {
slashCount = 1;
doRollover(
- randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip",
+ randomOutputDir + "/%d{" + CoreConstants.DAILY_DATE_PATTERN + "}/clean.%i.zip",
MILLIS_IN_DAY, 5, 5 * 4);
checkDirPatternCompliance(6);
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
index b69734d..f9e18c3 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
@@ -84,7 +84,7 @@ public class CompressTest {
compressor.setContext(context);
compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ "input/compress1.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
- + "compress1.txt.gz");
+ + "compress1.txt.gz", null);
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
@@ -99,7 +99,7 @@ public class CompressTest {
compressor.setContext(context);
compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ "input/compress2.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
- + "compress2.txt");
+ + "compress2.txt", null);
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
@@ -115,7 +115,7 @@ public class CompressTest {
compressor.setContext(context);
compressor.compress(CoreTestConstants.TEST_DIR_PREFIX
+ "input/compress3.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
- + "compress3.txt");
+ + "compress3.txt", "compress3.txt");
StatusChecker checker = new StatusChecker(context);
assertTrue(checker.isErrorFree());
diff --git a/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java b/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
index dd4143c..9126ced 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/testUtil/FileToBufferUtil.java
@@ -13,45 +13,61 @@
*/
package ch.qos.logback.core.testUtil;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.util.Enumeration;
import java.util.List;
import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
public class FileToBufferUtil {
static public void readIntoList(File file, List<String> stringList)
- throws IOException {
+ throws IOException {
- if(file.getName().endsWith(".gz")) {
+ if (file.getName().endsWith(".gz")) {
gzFileReadIntoList(file, stringList);
+ } else if (file.getName().endsWith(".zip")) {
+ zipFileReadIntoList(file, stringList);
+
} else {
regularReadIntoList(file, stringList);
}
}
-
- static public void regularReadIntoList(File file, List<String> stringList) throws IOException {
+
+ private static void zipFileReadIntoList(File file, List<String> stringList) throws IOException {
FileInputStream fis = new FileInputStream(file);
- BufferedReader in = new BufferedReader(new InputStreamReader(fis));
+ ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fis));
+ ZipFile zipFile = new ZipFile(file);
+ Enumeration entries = zipFile.entries();
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ readInputStream(zipFile.getInputStream(entry), stringList);
+ }
+
+ static void readInputStream(InputStream is, List<String> stringList) throws IOException {
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
- while( (line = in.readLine()) != null) {
+ while ((line = in.readLine()) != null) {
stringList.add(line);
}
in.close();
}
- static public void gzFileReadIntoList(File file, List<String> stringList) throws IOException {
+ static public void regularReadIntoList(File file, List<String> stringList) throws IOException {
FileInputStream fis = new FileInputStream(file);
- GZIPInputStream gzis = new GZIPInputStream(fis);
- BufferedReader in = new BufferedReader(new InputStreamReader(gzis));
+ BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String line;
- while( (line = in.readLine()) != null) {
+ while ((line = in.readLine()) != null) {
stringList.add(line);
}
in.close();
}
+ static public void gzFileReadIntoList(File file, List<String> stringList) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ GZIPInputStream gzis = new GZIPInputStream(fis);
+ readInputStream(gzis, stringList);
+ }
+
}
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/core/CoreConstants.java | 1 +
.../core/rolling/FixedWindowRollingPolicy.java | 26 ++++++---
.../logback/core/rolling/RollingPolicyBase.java | 2 +
...TimeBasedFileNamingAndTriggeringPolicyBase.java | 4 -
.../core/rolling/TimeBasedRollingPolicy.java | 33 +++++++----
.../rolling/helper/AsynchronousCompressor.java | 4 +-
.../core/rolling/helper/CompressionRunnable.java | 10 ++-
.../logback/core/rolling/helper/Compressor.java | 28 +++++++--
.../core/rolling/helper/DateTokenConverter.java | 5 +-
.../core/rolling/helper/DefaultArchiveRemover.java | 11 ++--
.../logback/core/rolling/SizeBasedRollingTest.java | 59 +++++++++++++++++++-
.../TimeBasedRollingWithArchiveRemovalTest.java | 14 +++--
.../logback/core/rolling/helper/CompressTest.java | 6 +-
.../logback/core/testUtil/FileToBufferUtil.java | 46 ++++++++++-----
14 files changed, 178 insertions(+), 71 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0