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
September 2011
- 9 participants
- 113 discussions

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.29-30-g9c732c9
by git-noreply@pixie.qos.ch 19 Sep '11
by git-noreply@pixie.qos.ch 19 Sep '11
19 Sep '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 9c732c91bbed4acc059d2242e76ed18ac6e7194b (commit)
via 904ba967f62651a3ae1163d18303afe412a7102c (commit)
via 082d5df90dc5e5a7181998134f59582274e53000 (commit)
via 1d001fc4640fc42b3bb1a34eafe492d62f55c17b (commit)
via 2ac4ee863fc4d3c74439a91a0d327e2aaf93543a (commit)
from 513fb2d00fecf03dc8bc561f9cdc2e49bc0d80df (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=9c732c91bbed4acc059d2242…
http://github.com/ceki/logback/commit/9c732c91bbed4acc059d2242e76ed18ac6e71…
commit 9c732c91bbed4acc059d2242e76ed18ac6e7194b
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Mon Sep 19 13:16:13 2011 +0200
disallow empty values to be returned by ILoggingEvent#getMDCPropertyMap
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
index 4b169bd..ce64e2f 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
@@ -70,7 +70,7 @@ public interface ILoggingEvent extends DeferredProcessingAware {
public Marker getMarker();
/**
- * Returns the MDC map.
+ * Returns the MDC map. The returned value can be an empty map but not null.
*/
public Map<String, String> getMDCPropertyMap();
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index 59dcf09..9581dc1 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -25,6 +25,7 @@ import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.LogbackMDCAdapter;
+import org.slf4j.spi.MDCAdapter;
/**
* The internal representation of logging events. When an affirmative decision
@@ -205,11 +206,7 @@ public class LoggingEvent implements ILoggingEvent {
this.getFormattedMessage();
this.getThreadName();
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
- if (mdcPropertyMap == null) {
- mdcPropertyMap = MDC.getCopyOfContextMap();
- if (mdcPropertyMap == null)
- mdcPropertyMap = CACHED_NULL_MAP;
- }
+ this.getMDCPropertyMap();
}
public LoggerContextVO getLoggerContextVO() {
@@ -307,17 +304,19 @@ public class LoggingEvent implements ILoggingEvent {
}
public Map<String, String> getMDCPropertyMap() {
+ // populate mdcPropertyMap if null
if (mdcPropertyMap == null) {
MDCAdapter mdc = MDC.getMDCAdapter();
if (mdc instanceof LogbackMDCAdapter)
- return ((LogbackMDCAdapter)mdc).getPropertyMap();
- else {
+ mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap();
+ else
mdcPropertyMap = mdc.getCopyOfContextMap();
- if (mdcPropertyMap == null)
- mdcPropertyMap = CACHED_NULL_MAP;
- }
}
- return mdcPropertyMap == CACHED_NULL_MAP ? null : mdcPropertyMap;
+ // mdcPropertyMap still null, use CACHED_NULL_MAP
+ if (mdcPropertyMap == null)
+ mdcPropertyMap = CACHED_NULL_MAP;
+
+ return mdcPropertyMap;
}
/**
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
index bfaa7de..02e5ba7 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
@@ -265,7 +265,7 @@ public class JaninoEventEvaluatorTest {
@Test
public void nullMDC() throws EvaluationException {
MDC.clear();
- jee.setExpression("mdc == null");
+ jee.setExpression("mdc.isEmpty()");
jee.start();
LoggingEvent event = makeLoggingEvent(null);
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/sift/MDCBasedDiscriminatorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/sift/MDCBasedDiscriminatorTest.java
index 395f542..edd0013 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/sift/MDCBasedDiscriminatorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/sift/MDCBasedDiscriminatorTest.java
@@ -25,6 +25,8 @@ import org.junit.Test;
import org.slf4j.MDC;
+import java.util.HashMap;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -71,7 +73,7 @@ public class MDCBasedDiscriminatorTest {
@Test
public void nullMDC() {
event = new LoggingEvent("a", logger, Level.DEBUG, "", null, null);
- assertNull(event.getMdc());
+ assertEquals(new HashMap(), event.getMDCPropertyMap());
String discriminatorValue = discriminator.getDiscriminatingValue(event);
assertEquals(DEFAULT_VAL, discriminatorValue);
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java
index e3f62c6..f759df2 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/spi/LoggingEventSerializationPerfTest.java
@@ -100,7 +100,7 @@ public class LoggingEventSerializationPerfTest {
long averageSize = (long) (noos.size() / (LOOP_LEN));
System.out.println("noos size " + noos.size() + " average size="
+ averageSize);
- double averageSizeLimit = 60;
+ double averageSizeLimit = 62.1;
assertTrue("average size " + averageSize + " should be less than "
+ averageSizeLimit, averageSizeLimit > averageSize);
diff --git a/logback-site/src/site/pages/manual/filters.html b/logback-site/src/site/pages/manual/filters.html
index bb931b7..0e67022 100644
--- a/logback-site/src/site/pages/manual/filters.html
+++ b/logback-site/src/site/pages/manual/filters.html
@@ -479,9 +479,9 @@ public class SampleFilter extends Filter>ILoggingEvent> {
<td><code>Map</code></td>
<td>A map containing all the MDC values at the time of the
creation of the logging event. A value can be accessed by
- using the following expression: <em>mdc.get("myKey")</em>. The
- 'mdc' variable can be null and this possibility should be
- checked for in evaluator expressions.
+ using the following expression: <em>mdc.get("myKey")</em>. As
+ of logback-classic version 0.9.30, the 'mdc' variable will
+ never be null.
<p>The <code>java.util.Map</code> type is non-parameterized
because Janino does not support generics. It follows that the
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 97ae9ad..2233c5e 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -44,6 +44,13 @@
of the <code>ILoggingEvent</code> interface in prior versions of
logback-classic.</p>
+ <p><code>LoggingEvent</code> no longer assumes that
+ <code>LogbackMDCAdapter</code> is the only possible implementation
+ of the <code>MDCAdapter</code> interface. This fixes <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-275">LBCLASSIC-275</a>
+ reported by Chris Dolan.
+ </p>
+
<p>It is now possible to specify multiple destination addresses
separated by commas in the the <span class="option">to</span>
property of <code>SMTPAppender</code>. This fixes <a
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=904ba967f62651a3ae1163d1…
http://github.com/ceki/logback/commit/904ba967f62651a3ae1163d18303afe412a71…
commit 904ba967f62651a3ae1163d18303afe412a7102c
Merge: 513fb2d 082d5df
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Mon Sep 19 03:03:31 2011 -0700
Merge pull request #17 from chrisdolan/master
LBCLASSIC-275 - LoggingEvent casts to LogbackMDCAdapter without checking
diff --cc logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index c2a0e1b,141ed3f..59dcf09
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@@ -309,15 -307,21 +307,25 @@@ public class LoggingEvent implements IL
}
public Map<String, String> getMDCPropertyMap() {
- return mdcPropertyMap;
+ if (mdcPropertyMap == null) {
+ MDCAdapter mdc = MDC.getMDCAdapter();
+ if (mdc instanceof LogbackMDCAdapter)
+ return ((LogbackMDCAdapter)mdc).getPropertyMap();
+ else {
+ mdcPropertyMap = mdc.getCopyOfContextMap();
+ if (mdcPropertyMap == null)
+ mdcPropertyMap = CACHED_NULL_MAP;
+ }
+ }
+ return mdcPropertyMap == CACHED_NULL_MAP ? null : mdcPropertyMap;
}
+ /**
+ * Synonym for [@link #getMDCPropertyMap}.
+ * @deprecated Replaced by [@link #getMDCPropertyMap}
+ */
public Map<String, String> getMdc() {
- return mdcPropertyMap;
+ return getMDCPropertyMap();
}
@Override
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=082d5df90dc5e5a718199813…
http://github.com/ceki/logback/commit/082d5df90dc5e5a7181998134f59582274e53…
commit 082d5df90dc5e5a7181998134f59582274e53000
Author: Chris Dolan <chris(a)chrisdolan.net>
Date: Mon Jun 13 14:29:50 2011 -0500
proper handling of null MDC in LoggingEvent caching
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index 6090f02..141ed3f 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -89,6 +89,7 @@ public class LoggingEvent implements ILoggingEvent {
private Marker marker;
private Map<String, String> mdcPropertyMap;
+ private static final Map<String, String> CACHED_NULL_MAP = new HashMap<String, String>();
/**
* The number of milliseconds elapsed from 1/1/1970 until logging event was
@@ -206,6 +207,8 @@ public class LoggingEvent implements ILoggingEvent {
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
if (mdcPropertyMap == null) {
mdcPropertyMap = MDC.getCopyOfContextMap();
+ if (mdcPropertyMap == null)
+ mdcPropertyMap = CACHED_NULL_MAP;
}
}
@@ -308,10 +311,13 @@ public class LoggingEvent implements ILoggingEvent {
MDCAdapter mdc = MDC.getMDCAdapter();
if (mdc instanceof LogbackMDCAdapter)
return ((LogbackMDCAdapter)mdc).getPropertyMap();
- else
+ else {
mdcPropertyMap = mdc.getCopyOfContextMap();
+ if (mdcPropertyMap == null)
+ mdcPropertyMap = CACHED_NULL_MAP;
+ }
}
- return mdcPropertyMap;
+ return mdcPropertyMap == CACHED_NULL_MAP ? null : mdcPropertyMap;
}
public Map<String, String> getMdc() {
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=1d001fc4640fc42b3bb1a34e…
http://github.com/ceki/logback/commit/1d001fc4640fc42b3bb1a34eafe492d62f55c…
commit 1d001fc4640fc42b3bb1a34eafe492d62f55c17b
Author: Chris Dolan <chris(a)chrisdolan.net>
Date: Mon Jun 13 14:15:30 2011 -0500
fix typo: mdcPropertyMap != null should have been mdcPropertyMap == null
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index c792217..6090f02 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -204,7 +204,7 @@ public class LoggingEvent implements ILoggingEvent {
this.getFormattedMessage();
this.getThreadName();
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
- if (mdcPropertyMap != null) {
+ if (mdcPropertyMap == null) {
mdcPropertyMap = MDC.getCopyOfContextMap();
}
}
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=2ac4ee863fc4d3c74439a91a…
http://github.com/ceki/logback/commit/2ac4ee863fc4d3c74439a91a0d327e2aaf935…
commit 2ac4ee863fc4d3c74439a91a0d327e2aaf93543a
Author: Chris Dolan <chris(a)chrisdolan.net>
Date: Mon Jun 13 09:34:05 2011 -0500
http://jira.qos.ch/browse/LBCLASSIC-275 - LoggingEvent casts to LogbackMDCAdapter without checking
Implementation of the proposal in the first comment of that issue: defer reading the MDC until as late as possible
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index d68e448..c792217 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -128,11 +128,6 @@ public class LoggingEvent implements ILoggingEvent {
}
timeStamp = System.currentTimeMillis();
-
- // ugly but under the circumstances acceptable
- LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC
- .getMDCAdapter();
- mdcPropertyMap = logbackMDCAdapter.getPropertyMap();
}
public void setArgumentArray(Object[] argArray) {
@@ -210,7 +205,7 @@ public class LoggingEvent implements ILoggingEvent {
this.getThreadName();
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
if (mdcPropertyMap != null) {
- mdcPropertyMap = new HashMap<String, String>(mdcPropertyMap);
+ mdcPropertyMap = MDC.getCopyOfContextMap();
}
}
@@ -309,11 +304,18 @@ public class LoggingEvent implements ILoggingEvent {
}
public Map<String, String> getMDCPropertyMap() {
+ if (mdcPropertyMap == null) {
+ MDCAdapter mdc = MDC.getMDCAdapter();
+ if (mdc instanceof LogbackMDCAdapter)
+ return ((LogbackMDCAdapter)mdc).getPropertyMap();
+ else
+ mdcPropertyMap = mdc.getCopyOfContextMap();
+ }
return mdcPropertyMap;
}
public Map<String, String> getMdc() {
- return mdcPropertyMap;
+ return getMDCPropertyMap();
}
@Override
-----------------------------------------------------------------------
Summary of changes:
.../ch/qos/logback/classic/spi/ILoggingEvent.java | 2 +-
.../ch/qos/logback/classic/spi/LoggingEvent.java | 25 ++++++++++++-------
.../classic/boolex/JaninoEventEvaluatorTest.java | 2 +-
.../classic/sift/MDCBasedDiscriminatorTest.java | 4 ++-
.../spi/LoggingEventSerializationPerfTest.java | 2 +-
logback-site/src/site/pages/manual/filters.html | 6 ++--
logback-site/src/site/pages/news.html | 7 +++++
7 files changed, 32 insertions(+), 16 deletions(-)
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.29-25-g513fb2d
by git-noreply@pixie.qos.ch 19 Sep '11
by git-noreply@pixie.qos.ch 19 Sep '11
19 Sep '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 513fb2d00fecf03dc8bc561f9cdc2e49bc0d80df (commit)
from 75da45d0f69a3877de3b3ab669c50ea6837ec996 (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=513fb2d00fecf03dc8bc561f…
http://github.com/ceki/logback/commit/513fb2d00fecf03dc8bc561f9cdc2e49bc0d8…
commit 513fb2d00fecf03dc8bc561f9cdc2e49bc0d80df
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Mon Sep 19 11:58:15 2011 +0200
The getMDC method is deprecated and replaced by getMDCPropertyMap.
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java b/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java
index 6b6b213..2fa8a1f 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java
@@ -47,7 +47,7 @@ public class MDCBasedDiscriminator extends ContextAwareBase implements
*/
public String getDiscriminatingValue(ILoggingEvent event) {
// http://jira.qos.ch/browse/LBCLASSIC-213
- Map<String, String> mdcMap = event.getMdc();
+ Map<String, String> mdcMap = event.getMDCPropertyMap();
if (mdcMap == null) {
return defaultValue;
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
index c5bd822..4b169bd 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
@@ -76,6 +76,7 @@ public interface ILoggingEvent extends DeferredProcessingAware {
/**
* Synonym for [@link #getMDCPropertyMap}.
+ * @deprecated Replaced by [@link #getMDCPropertyMap}
*/
public Map<String, String> getMdc();
public long getTimeStamp();
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
index 05fac34..c2a0e1b 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
@@ -312,6 +312,10 @@ public class LoggingEvent implements ILoggingEvent {
return mdcPropertyMap;
}
+ /**
+ * Synonym for [@link #getMDCPropertyMap}.
+ * @deprecated Replaced by [@link #getMDCPropertyMap}
+ */
public Map<String, String> getMdc() {
return mdcPropertyMap;
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
index fcc4d9b..4d494e9 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
@@ -37,6 +37,13 @@ import org.slf4j.spi.MDCAdapter;
*/
public final class LogbackMDCAdapter implements MDCAdapter {
+ // We wish to avoid unnecessarily copying of the map. To ensure
+ // efficient/timely copying, we have a variable keeping track of the last
+ // operation. A copy is necessary on 'put' or 'remove' but only if the last
+ // operation was a 'get'. Get operations never necessitate a copy nor
+ // successive 'put/remove' operations, only a get followed by a 'put/remove'
+ // requires copying the map.
+ // See http://jira.qos.ch/browse/LBCLASSIC-254 for the original discussion.
// We no longer use CopyOnInheritThreadLocal in order to solve LBCLASSIC-183
// Initially the contents of the thread local in parent and child threads
@@ -170,6 +177,9 @@ public final class LogbackMDCAdapter implements MDCAdapter {
* null.
*/
public Map getCopyOfContextMap() {
+ // why aren't we setting lastOperation as follows?
+ // lastOperation.set(READ_OPERATION);
+
HashMap<String, String> hashMap = copyOnInheritThreadLocal.get();
if (hashMap == null) {
return null;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
index feade42..d9eb252 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
@@ -138,7 +138,7 @@ public class Loader {
}
/**
- * Returns the class loader of clazz if
+ * Returns the class loader of clazz in an access privileged section.
* @param clazz
* @return
*/
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 713ea7b..97ae9ad 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -28,7 +28,21 @@
<hr width="80%" align="center" />
- <h3>July xxx, 2011 - Release of version 0.9.30</h3>
+ <h3>September xxx, 2011 - Release of version 0.9.30</h3>
+
+
+ <p>Archive removal can now deal with prolonged periods of
+ application inactivity and application stop and restarts. The
+ issue is described in <a
+ href="http://jira.qos.ch/browse/LBCORE-147">LBCORE-147</a>
+ reported by Rafael Diaz Maurin.
+ </p>
+
+ <p>In the <code>ILoggingEvent</code> interface the
+ <code>getMDC</code> method is now deprecated and replaced by
+ <code>getMDCPropertyMap</code>. The latter methof was already part
+ of the <code>ILoggingEvent</code> interface in prior versions of
+ logback-classic.</p>
<p>It is now possible to specify multiple destination addresses
separated by commas in the the <span class="option">to</span>
-----------------------------------------------------------------------
Summary of changes:
.../classic/sift/MDCBasedDiscriminator.java | 2 +-
.../ch/qos/logback/classic/spi/ILoggingEvent.java | 1 +
.../ch/qos/logback/classic/spi/LoggingEvent.java | 4 ++++
.../logback/classic/util/LogbackMDCAdapter.java | 10 ++++++++++
.../main/java/ch/qos/logback/core/util/Loader.java | 2 +-
logback-site/src/site/pages/news.html | 16 +++++++++++++++-
6 files changed, 32 insertions(+), 3 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0

11 Sep '11
Logback Classic causes SecurityException
----------------------------------------
Key: LBCLASSIC-263
URL: http://jira.qos.ch/browse/LBCLASSIC-263
Project: logback-classic
Issue Type: Bug
Affects Versions: 0.9.28
Reporter: NC
Assignee: Logback dev list
PackagingDataCalculator invokes Class.getClassLoader(). This method throws a SecurityException when running under a security manager and that manager denies access to the ClassLoader.
I'm submitting a PackagingDataCalculator patch which wraps the getClassLoader() invocation in a doPrivileged block. This allows these calls to succeed when the getClassLoader RuntimePermission is granted to logback-classic.
--
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
8

[JIRA] Created: (LBCLASSIC-294) <if> requires Janino, which is considered harmful
by Joachim Durchholz (JIRA) 09 Sep '11
by Joachim Durchholz (JIRA) 09 Sep '11
09 Sep '11
<if> requires Janino, which is considered harmful
-------------------------------------------------
Key: LBCLASSIC-294
URL: http://jira.qos.ch/browse/LBCLASSIC-294
Project: logback-classic
Issue Type: Improvement
Components: joran
Affects Versions: 0.9.29
Environment: (Assuming 0.9.29 is the currently released version)
Reporter: Joachim Durchholz
Assignee: Logback dev list
Priority: Blocker
More on Janino below, here's the proposal:
Have a variant of <if>, namely <if property="property name">.
If the property does not exist or is false, use the <else> part, otherwise, use the <then> part.
Problems with Janino:
1) Bloat. A footprint of 1 megabyte is amazingly small for an almost full Java compiler, but it still more than doubles the footprint for logging.
2) Reliability. If the logging configuration is user editable, they might add a Java expression that calls arbitrary internal APIs.
I am aware that http://logback.qos.ch/manual/configuration.html#conditional claims that the generated code is sandboxed ("only context properties or system properties are accessible"). However, sandboxes require full security audits. Janino would require a security audit. I doubt that there are enough developer resources for this task available; the task could be reduced for Logback by keeping the available API narrow (just a bunch of properties is extremely tight), but I doubt that that is possible for Janino.
Worse, those audits would need to be repeated for every new revision.
3) Security. Expressions that make it outside the sandbox could do any amount of nasty things. Intentionally or not (I can imagine scenarios for both).
These problems do not exist for programmer-defined properties. Only PropertyDefiner descendants can be called from the configuration, and these are statically checkable in source. There is no need to worry about expressions that might try to call arbitrary internal APIs.
(If I wanted to live with that kind of risk I'd be programming in Lisp, dammit!)
--
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: (LBCLASSIC-292) Support optional include files
by Joachim Durchholz (JIRA) 09 Sep '11
by Joachim Durchholz (JIRA) 09 Sep '11
09 Sep '11
Support optional include files
------------------------------
Key: LBCLASSIC-292
URL: http://jira.qos.ch/browse/LBCLASSIC-292
Project: logback-classic
Issue Type: Improvement
Components: joran
Affects Versions: 0.9.26
Reporter: Joachim Durchholz
Assignee: Logback dev list
Priority: Minor
Logback emits a warning if a file named in <include/> isn't present.
Sometimes, an included configuration file is purely optional. E.g. I would want to mail a more verbose configuration to a customer who has some mysterious error where the standard logging simply isn't detailed enough.
Unfortunately, this means that in the standard case, I'll be spammed with the missing file warning, plus heaps of INFO messages. This might distract from relevant logback configuration problems.
Suggestion: extend <include/> so that it accepts <include optional="true" ... />. If an include is optional, it will not generate error messages if the requested configuration is not present.
The loading code might want to differentiate between "does not exist" (to suppress the message) and other problems (which probably should still be reported).
--
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
4

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.29-24-g75da45d
by git-noreply@pixie.qos.ch 08 Sep '11
by git-noreply@pixie.qos.ch 08 Sep '11
08 Sep '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 75da45d0f69a3877de3b3ab669c50ea6837ec996 (commit)
from 039eb9e9b9987b36f4e44fdab7967aea71810cd2 (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=75da45d0f69a3877de3b3ab6…
http://github.com/ceki/logback/commit/75da45d0f69a3877de3b3ab669c50ea6837ec…
commit 75da45d0f69a3877de3b3ab669c50ea6837ec996
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Thu Sep 8 22:25:06 2011 +0200
LBCLASSIC-263 and LBCLASSIC-292
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
index c2d4da5..f9c5ba8 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
@@ -16,12 +16,12 @@ package ch.qos.logback.classic.spi;
import java.net.URL;
import java.util.HashMap;
+import ch.qos.logback.core.util.Loader;
import sun.reflect.Reflection;
-
+// import java.security.AccessControlException; import java.security.AccessController;import java.security.PrivilegedAction;
/**
- *
* Given a classname locate associated PackageInfo (jar name, version name).
- *
+ *
* @author James Strachan
* @Ceki Gülcü
*/
@@ -31,7 +31,7 @@ public class PackagingDataCalculator {
HashMap<String, ClassPackagingData> cache = new HashMap<String, ClassPackagingData>();
- private static boolean GET_CALLER_CLASS_METHOD_AVAILABLE = false;
+ private static boolean GET_CALLER_CLASS_METHOD_AVAILABLE = false; //private static boolean HAS_GET_CLASS_LOADER_PERMISSION = false;
static {
// if either the Reflection class or the getCallerClass method
@@ -50,6 +50,7 @@ public class PackagingDataCalculator {
}
}
+
public PackagingDataCalculator() {
}
@@ -66,7 +67,7 @@ public class PackagingDataCalculator {
final Throwable t = new Throwable("local stack reference");
final StackTraceElement[] localteSTEArray = t.getStackTrace();
final int commonFrames = STEUtil.findNumberOfCommonFrames(localteSTEArray,
- stepArray);
+ stepArray);
final int localFirstCommon = localteSTEArray.length - commonFrames;
final int stepFirstCommon = stepArray.length - commonFrames;
@@ -78,12 +79,13 @@ public class PackagingDataCalculator {
Class callerClass = null;
if (GET_CALLER_CLASS_METHOD_AVAILABLE) {
callerClass = Reflection.getCallerClass(localFirstCommon + i
- - missfireCount + 1);
+ - missfireCount + 1);
}
StackTraceElementProxy step = stepArray[stepFirstCommon + i];
String stepClassname = step.ste.getClassName();
if (callerClass != null && stepClassname.equals(callerClass.getName())) {
+ // see also LBCLASSIC-263
lastExactClassLoader = callerClass.getClassLoader();
if (firsExactClassLoader == null) {
firsExactClassLoader = lastExactClassLoader;
@@ -100,7 +102,7 @@ public class PackagingDataCalculator {
}
void populateUncommonFrames(int commonFrames,
- StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) {
+ StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) {
int uncommonFrames = stepArray.length - commonFrames;
for (int i = 0; i < uncommonFrames; i++) {
StackTraceElementProxy step = stepArray[i];
@@ -123,7 +125,7 @@ public class PackagingDataCalculator {
}
private ClassPackagingData computeBySTEP(StackTraceElementProxy step,
- ClassLoader lastExactClassLoader) {
+ ClassLoader lastExactClassLoader) {
String className = step.ste.getClassName();
ClassPackagingData cpd = cache.get(className);
if (cpd != null) {
@@ -208,15 +210,12 @@ public class PackagingDataCalculator {
}
/**
- *
- * @param lastGuaranteedClassLoader
- * may be null
- *
+ * @param lastGuaranteedClassLoader may be null
* @param className
* @return
*/
private Class bestEffortLoadClass(ClassLoader lastGuaranteedClassLoader,
- String className) {
+ String className) {
Class result = loadClass(lastGuaranteedClassLoader, className);
if (result != null) {
return result;
diff --git a/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml b/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
new file mode 100644
index 0000000..f39b5f5
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
@@ -0,0 +1,14 @@
+
+<configuration>
+
+ <define name="INCLUDED_FILE_EXISTS"
+ class="ch.qos.logback.core.property.FileExistsPropertyDefiner">
+ <path>src/test/input/joran/conditional/includedFile.xml</path>
+ </define>
+
+ <if condition='property("INCLUDED_FILE_EXISTS").equals("true")'>
+ <then>
+ <include file="src/test/input/joran/conditional/includedFile.xml"/>
+ </then>
+ </if>
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml b/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
new file mode 100644
index 0000000..6cbf0af
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
@@ -0,0 +1,14 @@
+
+<configuration>
+
+ <define name="INCLUDED_FILE_EXISTS"
+ class="ch.qos.logback.core.property.FileExistsPropertyDefiner">
+ <path>src/test/input/joran/conditional/inexistent.xml</path>
+ </define>
+
+ <if condition='property("INCLUDED_FILE_EXISTS").equals("true")'>
+ <then>
+ <include file="src/test/input/joran/conditional/inexistent.xml"/>
+ </then>
+ </if>
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/input/joran/conditional/includedFile.xml b/logback-classic/src/test/input/joran/conditional/includedFile.xml
new file mode 100644
index 0000000..703102c
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/includedFile.xml
@@ -0,0 +1,10 @@
+<included>
+ <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d %-5level %logger{35} - %msg %n</pattern>
+ </encoder>
+ </appender>
+ <root>
+ <appender-ref ref="CON"/>
+ </root>
+</included>
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
index 1d4ee9c..0fe480e 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
@@ -123,4 +123,35 @@ public class ConditionalTest {
assertTrue(checker.isErrorFree(0));
}
+ @Test
+ public void conditionalInclusionWithExistingFile() throws JoranException,
+ IOException, InterruptedException {
+
+ String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+ + "conditional/conditionalIncludeExistingFile.xml";
+ configure(configFileAsStr);
+
+ StatusPrinter.print(context);
+ ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
+ assertNotNull(consoleAppender);
+ StatusChecker checker = new StatusChecker(context);
+ assertTrue(checker.isErrorFree(0));
+ }
+ @Test
+
+ public void conditionalInclusionWithInexistentFile() throws JoranException,
+ IOException, InterruptedException {
+
+ String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+ + "conditional/conditionalIncludeInexistentFile.xml";
+ configure(configFileAsStr);
+
+ StatusPrinter.print(context);
+ ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
+ assertNull(consoleAppender);
+ StatusChecker checker = new StatusChecker(context);
+ assertTrue(checker.isErrorFree(0));
+ }
+
+
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
index aba52e3..b805334 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
@@ -91,8 +91,12 @@ public class DefinePropertyAction extends Action {
addInfo("Popping property definer for property named [" + propertyName
+ "] from the object stack");
ec.popObject();
- // let's put defined property and value to context
- context.putProperty(propertyName, definer.getPropertyValue());
+ // let's put defined property and value to context but only if it is
+ // not null
+ String propertyValue = definer.getPropertyValue();
+ if(propertyValue != null) {
+ context.putProperty(propertyName, propertyValue);
+ }
}
}
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java
new file mode 100644
index 0000000..89b16e7
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java
@@ -0,0 +1,31 @@
+package ch.qos.logback.core.property;
+
+import ch.qos.logback.core.PropertyDefinerBase;
+import java.io.File;
+
+/**
+ * @author Ceki Gücü
+ */
+public class FileExistsPropertyDefiner extends PropertyDefinerBase {
+
+ String path;
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getPropertyValue() {
+ if(path == null)
+ return "false";
+ File file = new File(path);
+ System.out.println(file.getAbsolutePath());
+ if(file.exists())
+ return "true";
+ else
+ return "false";
+ }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
index cd610a3..feade42 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
@@ -15,6 +15,9 @@ package ch.qos.logback.core.util;
import java.io.IOException;
import java.net.URL;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -23,7 +26,7 @@ import ch.qos.logback.core.Context;
/**
* Load resources (or images) from various sources.
- *
+ *
* @author Ceki Gülcü
*/
public class Loader {
@@ -31,28 +34,41 @@ public class Loader {
private static boolean ignoreTCL = false;
public static final String IGNORE_TCL_PROPERTY_NAME = "logback.ignoreTCL";
+ private static boolean HAS_GET_CLASS_LOADER_PERMISSION = false;
static {
-
String ignoreTCLProp = OptionHelper.getSystemProperty(
- IGNORE_TCL_PROPERTY_NAME, null);
+ IGNORE_TCL_PROPERTY_NAME, null);
if (ignoreTCLProp != null) {
ignoreTCL = OptionHelper.toBoolean(ignoreTCLProp, true);
}
+
+ HAS_GET_CLASS_LOADER_PERMISSION =
+ AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ try {
+ AccessController.checkPermission(
+ new RuntimePermission("getClassLoader"));
+ return true;
+ } catch (AccessControlException e) {
+ return false;
+ }
+ }
+ });
}
/**
* Compute the number of occurrences a resource can be found by a class
* loader.
- *
+ *
* @param resource
* @param classLoader
* @return
* @throws IOException
*/
public static List<URL> getResourceOccurenceCount(String resource,
- ClassLoader classLoader) throws IOException {
+ ClassLoader classLoader) throws IOException {
List<URL> urlList = new ArrayList<URL>();
Enumeration<URL> urlEnum = classLoader.getResources(resource);
while (urlEnum.hasMoreElements()) {
@@ -65,11 +81,9 @@ public class Loader {
/**
* Search for a resource using the classloader passed as parameter.
- *
- * @param resource
- * the resource name to look for
- * @param classLoader
- * the classloader used for the search
+ *
+ * @param resource the resource name to look for
+ * @param classLoader the classloader used for the search
*/
public static URL getResource(String resource, ClassLoader classLoader) {
try {
@@ -82,7 +96,7 @@ public class Loader {
/**
* Attempt to find a resource by using the classloader that loaded this class,
* namely Loader.class.
- *
+ *
* @param resource
* @return
*/
@@ -98,14 +112,13 @@ public class Loader {
* Get the Thread Context Loader which is a JDK 1.2 feature. If we are running
* under JDK 1.1 or anything else goes wrong the method returns
* <code>null<code>.
- *
*/
public static ClassLoader getTCL() {
return Thread.currentThread().getContextClassLoader();
}
public static Class loadClass(String clazz, Context context)
- throws ClassNotFoundException {
+ throws ClassNotFoundException {
ClassLoader cl = getClassLoaderOfObject(context);
return cl.loadClass(clazz);
}
@@ -113,7 +126,7 @@ public class Loader {
/**
* Get the class loader of the object passed as argument. Return the system
* class loader if appropriate.
- *
+ *
* @param o
* @return
*/
@@ -125,13 +138,30 @@ public class Loader {
}
/**
+ * Returns the class loader of clazz if
+ * @param clazz
+ * @return
+ */
+ public static ClassLoader getClassLoaderAsPrivileged(final Class clazz) {
+ if (!HAS_GET_CLASS_LOADER_PERMISSION)
+ return null;
+ else
+ return AccessController.doPrivileged(
+ new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+
+ /**
* Return the class loader which loaded the class passed as argument. Return
* the system class loader if appropriate.
- *
+ *
* @param clazz
* @return
*/
- public static ClassLoader getClassLoaderOfClass(Class clazz) {
+ public static ClassLoader getClassLoaderOfClass(final Class clazz) {
ClassLoader cl = clazz.getClassLoader();
if (cl == null) {
return ClassLoader.getSystemClassLoader();
@@ -144,7 +174,6 @@ public class Loader {
* If running under JDK 1.2 load the specified class using the
* <code>Thread</code> <code>contextClassLoader</code> if that fails try
* Class.forname. Under JDK 1.1 only Class.forName is used.
- *
*/
public static Class loadClass(String clazz) throws ClassNotFoundException {
// Just call Class.forName(clazz) if we are running under JDK 1.1
-----------------------------------------------------------------------
Summary of changes:
.../classic/spi/PackagingDataCalculator.java | 25 ++++----
.../conditional/conditionalIncludeExistingFile.xml | 14 ++++
.../conditionalIncludeInexistentFile.xml | 14 ++++
.../test/input/joran/conditional/includedFile.xml | 10 +++
.../classic/joran/conditional/ConditionalTest.java | 31 ++++++++++
.../core/joran/action/DefinePropertyAction.java | 8 ++-
.../core/property/FileExistsPropertyDefiner.java | 31 ++++++++++
.../main/java/ch/qos/logback/core/util/Loader.java | 63 ++++++++++++++-----
8 files changed, 164 insertions(+), 32 deletions(-)
create mode 100644 logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
create mode 100644 logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
create mode 100644 logback-classic/src/test/input/joran/conditional/includedFile.xml
create mode 100644 logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0

[JIRA] Created: (LBCLASSIC-293) scan/include interaction is not described
by Joachim Durchholz (JIRA) 08 Sep '11
by Joachim Durchholz (JIRA) 08 Sep '11
08 Sep '11
scan/include interaction is not described
-----------------------------------------
Key: LBCLASSIC-293
URL: http://jira.qos.ch/browse/LBCLASSIC-293
Project: logback-classic
Issue Type: Improvement
Components: joran
Affects Versions: 0.9.29
Reporter: Joachim Durchholz
Assignee: Logback dev list
Priority: Trivial
http://logback.qos.ch/manual/configuration.html does not tell whether it applies to included configuration files as well.
(I understand it did not initially and has been doing since some specific revision.)
I guess configuration.html should be changed to talk about configuration files in the plural form, and explain that there's an <include> directive near the top.
--
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
1

[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.29-23-g039eb9e
by git-noreply@pixie.qos.ch 07 Sep '11
by git-noreply@pixie.qos.ch 07 Sep '11
07 Sep '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 039eb9e9b9987b36f4e44fdab7967aea71810cd2 (commit)
from 524e0fc13ecc4fb24d1e2515adc47d8711cf3654 (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=039eb9e9b9987b36f4e44fda…
http://github.com/ceki/logback/commit/039eb9e9b9987b36f4e44fdab7967aea71810…
commit 039eb9e9b9987b36f4e44fdab7967aea71810cd2
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Wed Sep 7 23:36:59 2011 +0200
minor improvements
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
index 49101f8..1947c84 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
@@ -31,7 +31,7 @@ public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends
@Override
public void start() {
super.start();
- archiveRemover = new TimeBasedArchiveRemover(tbrp.fileNamePattern, rc, getCurrentTime());
+ archiveRemover = new TimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
archiveRemover.setContext(context);
started = true;
}
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 128de48..352f5ac 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
@@ -47,6 +47,8 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements
long periodsElapsed = 0;
if (lastHeartBeat == UNINITIALIZED) {
periodsElapsed = rc.periodsElapsed(nowInMillis, nowInMillis + INACTIVITY_TOLERANCE_IN_MILLIS);
+ if (periodsElapsed > MAX_VALUE_FOR_INACTIVITY_PERIODS)
+ periodsElapsed = MAX_VALUE_FOR_INACTIVITY_PERIODS;
} else {
periodsElapsed = rc.periodsElapsed(lastHeartBeat, nowInMillis);
if (periodsElapsed < 1) {
@@ -54,8 +56,6 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements
periodsElapsed = 1;
}
}
- if (periodsElapsed > MAX_VALUE_FOR_INACTIVITY_PERIODS)
- periodsElapsed = MAX_VALUE_FOR_INACTIVITY_PERIODS;
return (int) periodsElapsed;
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
index a79f481..a44b65a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
@@ -24,7 +24,7 @@ import org.codehaus.groovy.tools.shell.util.NoExitSecurityManager;
public class TimeBasedArchiveRemover extends DefaultArchiveRemover {
public TimeBasedArchiveRemover(FileNamePattern fileNamePattern,
- RollingCalendar rc, long currentTime) {
+ RollingCalendar rc) {
super(fileNamePattern, rc);
}
-----------------------------------------------------------------------
Summary of changes:
...aultTimeBasedFileNamingAndTriggeringPolicy.java | 2 +-
.../core/rolling/helper/DefaultArchiveRemover.java | 4 ++--
.../rolling/helper/TimeBasedArchiveRemover.java | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
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.29-22-g524e0fc
by git-noreply@pixie.qos.ch 06 Sep '11
by git-noreply@pixie.qos.ch 06 Sep '11
06 Sep '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 524e0fc13ecc4fb24d1e2515adc47d8711cf3654 (commit)
from 6f2735660d8c650b7be9e682c2fe85764592a340 (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=524e0fc13ecc4fb24d1e2515…
http://github.com/ceki/logback/commit/524e0fc13ecc4fb24d1e2515adc47d8711cf3…
commit 524e0fc13ecc4fb24d1e2515adc47d8711cf3654
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Tue Sep 6 22:00:31 2011 +0200
fixing LBCORE-147 and adding relavant test cases
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
index 9e9d7b1..c2d4da5 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
@@ -86,7 +86,7 @@ public class PackagingDataCalculator {
if (callerClass != null && stepClassname.equals(callerClass.getName())) {
lastExactClassLoader = callerClass.getClassLoader();
if (firsExactClassLoader == null) {
- firsExactClassLoader = callerClass.getClassLoader();
+ firsExactClassLoader = lastExactClassLoader;
}
ClassPackagingData pi = calculateByExactType(callerClass);
step.setClassPackagingData(pi);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
index 0c2c44a..bda2ad2 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
@@ -35,7 +35,7 @@ public class SizeAndTimeBasedFNATP<E> extends
// in super.start()
super.start();
- archiveRemover = new SizeAndTimeBasedArchiveRemover(tbrp.fileNamePattern, rc, getCurrentTime());
+ archiveRemover = new SizeAndTimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
archiveRemover.setContext(context);
// we need to get the correct value of currentPeriodsCounter.
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 7fbcf50..128de48 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
@@ -16,28 +16,63 @@ package ch.qos.logback.core.rolling.helper;
import java.io.File;
import java.util.Date;
+import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.pattern.Converter;
import ch.qos.logback.core.pattern.LiteralConverter;
import ch.qos.logback.core.spi.ContextAwareBase;
abstract public class DefaultArchiveRemover extends ContextAwareBase implements
- ArchiveRemover {
+ ArchiveRemover {
+
+ static protected final long UNINITIALIZED = -1;
+ // aim for 64 days, except in case of hourly rollover
+ static protected final long INACTIVITY_TOLERANCE_IN_MILLIS = 64L * (long) CoreConstants.MILLIS_IN_ONE_DAY;
+ static final int MAX_VALUE_FOR_INACTIVITY_PERIODS = 14 * 24; // 14 days in case of hourly rollover
final FileNamePattern fileNamePattern;
final RollingCalendar rc;
int periodOffsetForDeletionTarget;
final boolean parentClean;
- long lastHeartBeat;
+ long lastHeartBeat = UNINITIALIZED;
public DefaultArchiveRemover(FileNamePattern fileNamePattern,
- RollingCalendar rc, long currentTime) {
+ RollingCalendar rc) {
this.fileNamePattern = fileNamePattern;
this.rc = rc;
this.parentClean = computeParentCleaningFlag(fileNamePattern);
- this.lastHeartBeat = currentTime;
}
+ int computeElapsedPeriodsSinceLastClean(long nowInMillis) {
+ long periodsElapsed = 0;
+ if (lastHeartBeat == UNINITIALIZED) {
+ periodsElapsed = rc.periodsElapsed(nowInMillis, nowInMillis + INACTIVITY_TOLERANCE_IN_MILLIS);
+ } else {
+ periodsElapsed = rc.periodsElapsed(lastHeartBeat, nowInMillis);
+ if (periodsElapsed < 1) {
+ addWarn("Unexpected periodsElapsed value " + periodsElapsed);
+ periodsElapsed = 1;
+ }
+ }
+ if (periodsElapsed > MAX_VALUE_FOR_INACTIVITY_PERIODS)
+ periodsElapsed = MAX_VALUE_FOR_INACTIVITY_PERIODS;
+ return (int) periodsElapsed;
+ }
+
+ public void clean(Date now) {
+ long nowInMillis = now.getTime();
+ int periodsElapsed = computeElapsedPeriodsSinceLastClean(nowInMillis);
+ lastHeartBeat = nowInMillis;
+ if (periodsElapsed > 1) {
+ addInfo("periodsElapsed = " + periodsElapsed);
+ }
+ for (int i = 0; i < periodsElapsed; i++) {
+ if (periodsElapsed > 1) addInfo("i = " + i);
+ cleanByPeriodOffset(now, periodOffsetForDeletionTarget - i);
+ }
+ }
+
+ abstract void cleanByPeriodOffset(Date now, int periodOffset);
boolean computeParentCleaningFlag(FileNamePattern fileNamePattern) {
DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
@@ -80,7 +115,7 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements
* Will remove the directory passed as parameter if empty. After that, if the
* parent is also becomes empty, remove the parent dir as well but at most 3
* times.
- *
+ *
* @param dir
* @param depth
*/
@@ -90,7 +125,7 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements
return;
}
if (dir.isDirectory() && FileFilterUtil.isEmptyDirectory(dir)) {
- addInfo("deleting folder [" + dir +"]");
+ addInfo("deleting folder [" + dir + "]");
dir.delete();
removeFolderIfEmpty(dir.getParentFile(), depth + 1);
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
index bece6c3..329ba8b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
@@ -65,7 +65,7 @@ public class FileFilterUtil {
/**
* Return the set of files matching the stemRegex as found in 'directory'. A
- * stemRegex does not contain any slash characters or any folder seperators.
+ * stemRegex does not contain any slash characters or any folder separators.
*
* @param file
* @param stemRegex
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RollingCalendar.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RollingCalendar.java
index cd6850c..d4bd02b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RollingCalendar.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RollingCalendar.java
@@ -140,7 +140,7 @@ public class RollingCalendar extends GregorianCalendar {
}
}
- public int periodsElapsed(long start, long end) {
+ public long periodsElapsed(long start, long end) {
if (start > end)
throw new IllegalArgumentException("Start cannot come before end");
@@ -148,17 +148,17 @@ public class RollingCalendar extends GregorianCalendar {
switch (periodicityType) {
case TOP_OF_MILLISECOND:
- return (int) diff;
+ return diff;
case TOP_OF_SECOND:
- return (int) diff / CoreConstants.MILLIS_IN_ONE_SECOND;
+ return diff / CoreConstants.MILLIS_IN_ONE_SECOND;
case TOP_OF_MINUTE:
- return (int) diff / CoreConstants.MILLIS_IN_ONE_MINUTE;
+ return diff / CoreConstants.MILLIS_IN_ONE_MINUTE;
case TOP_OF_HOUR:
return (int) diff / CoreConstants.MILLIS_IN_ONE_HOUR;
case TOP_OF_DAY:
- return (int) diff / CoreConstants.MILLIS_IN_ONE_DAY;
+ return diff / CoreConstants.MILLIS_IN_ONE_DAY;
case TOP_OF_WEEK:
- return (int) diff / CoreConstants.MILLIS_IN_ONE_WEEK;
+ return diff / CoreConstants.MILLIS_IN_ONE_WEEK;
case TOP_OF_MONTH:
return diffInMonths(start, end);
default:
@@ -166,7 +166,7 @@ public class RollingCalendar extends GregorianCalendar {
}
}
- public static int diffInMonths(Long startTime, Long endTime) {
+ public static int diffInMonths(long startTime, long endTime) {
if (startTime > endTime)
throw new IllegalArgumentException("startTime cannot be larger than endTime");
Calendar startCal = Calendar.getInstance();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
index 1bb90d4..858ca47 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
@@ -19,12 +19,12 @@ import java.util.Date;
public class SizeAndTimeBasedArchiveRemover extends DefaultArchiveRemover {
public SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern,
- RollingCalendar rc, long currentTime) {
- super(fileNamePattern, rc, currentTime);
+ RollingCalendar rc) {
+ super(fileNamePattern, rc);
}
- public void clean(Date now) {
- Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffsetForDeletionTarget);
+ public void cleanByPeriodOffset(Date now, int periodOffset) {
+ Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffset);
String regex = fileNamePattern.toRegex(dateOfPeriodToClean);
String stemRegex = FileFilterUtil.afterLastSlash(regex);
@@ -47,4 +47,5 @@ public class SizeAndTimeBasedArchiveRemover extends DefaultArchiveRemover {
}
}
+
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
index 01ff76e..a79f481 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java
@@ -25,21 +25,7 @@ public class TimeBasedArchiveRemover extends DefaultArchiveRemover {
public TimeBasedArchiveRemover(FileNamePattern fileNamePattern,
RollingCalendar rc, long currentTime) {
- super(fileNamePattern, rc, currentTime);
- }
-
-
- public void clean(Date now) {
- long nowInMillis = now.getTime();
- int periodsElapsed = rc.periodsElapsed(lastHeartBeat, nowInMillis);
- if(periodsElapsed < 1) {
- addWarn("Unexpected periodsElapsed value "+periodsElapsed);
- periodsElapsed = 1;
- }
- lastHeartBeat = nowInMillis;
- for(int i=0; i < periodsElapsed; i++) {
- cleanByPeriodOffset(now, periodOffsetForDeletionTarget-i);
- }
+ super(fileNamePattern, rc);
}
protected void cleanByPeriodOffset(Date now, int periodOffset) {
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
deleted file mode 100644
index 7f75422..0000000
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2011, 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.core.rolling;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static ch.qos.logback.core.CoreConstants.DAILY_DATE_PATTERN;
-import ch.qos.logback.core.util.StatusPrinter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.encoder.EchoEncoder;
-import ch.qos.logback.core.testUtil.RandomUtil;
-import ch.qos.logback.core.util.CoreTestConstants;
-
-public class TimeBasedRollingWithArchiveRemovalTest {
-
- Context context = new ContextBase();
- EchoEncoder<Object> encoder = new EchoEncoder<Object>();
-
- static final String MONTHLY_DATE_PATTERN = "yyyy-MM";
- static final String MONTHLY_CROLOLOG_DATE_PATTERN = "yyyy/MM";
-
- static final String DAILY_CROLOLOG_DATE_PATTERN = "yyyy/MM/dd";
-
- static final long MILLIS_IN_MINUTE = 60 * 1000;
- static final long MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
- static final long MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
- static final long MILLIS_IN_MONTH = (long) ((365.0/12) * MILLIS_IN_DAY);
-
- int diff = RandomUtil.getPositiveInt();
- protected String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff
- + "/";
- int slashCount;
-
- // by default tbfnatp is an instance of
- // DefaultTimeBasedFileNamingAndTriggeringPolicy
- TimeBasedFileNamingAndTriggeringPolicy<Object> tbfnatp = new DefaultTimeBasedFileNamingAndTriggeringPolicy<Object>();
-
- @Before
- public void setUp() {
- context.setName("test");
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- int computeSlashCount(String datePattern) {
- int fromIndex = 0;
- int count = 0;
- while (true) {
- int i = datePattern.indexOf('/', fromIndex);
- if (i == -1) {
- break;
- } else {
- count++;
- fromIndex = i + 1;
- if (fromIndex >= datePattern.length()) {
- break;
- }
- }
- }
- return count;
- }
-
- @Test
- public void montlyRollover() throws Exception {
- slashCount = computeSlashCount(MONTHLY_DATE_PATTERN);
- // large maxPeriod, a 3 times as many number of periods to simulate
- doRollover(randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt",
- MILLIS_IN_MONTH, 20, 20 * 3);
- check(expectedCountWithoutFolders(20));
- }
-
- @Test
- public void montlyRolloverOverManyPeriods() throws Exception {
- System.out.println("randomOutputDir=" + randomOutputDir);
- // small maxHistory, many periods
- slashCount = computeSlashCount(MONTHLY_CROLOLOG_DATE_PATTERN);
-
- int numPeriods = 40;
- int maxHistory = 2;
-
- doRollover(randomOutputDir + "/%d{" + MONTHLY_CROLOLOG_DATE_PATTERN
- + "}/clean.txt.zip", MILLIS_IN_MONTH, maxHistory, numPeriods);
- int beginPeriod = Calendar.getInstance().get(Calendar.MONTH);
- boolean extraFolder = extraFolder(numPeriods, 12, beginPeriod, maxHistory);
- System.out.println("xxxx slashCount="+slashCount+", extraFolder="+extraFolder);
- StatusPrinter.print(context);
- check(expectedCountWithFolders(2, extraFolder));
- }
-
- @Test
- public void dailyRollover() throws Exception {
- slashCount = computeSlashCount(DAILY_DATE_PATTERN);
- doRollover(
- randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip",
- MILLIS_IN_DAY, 5, 5 * 3);
- check(expectedCountWithoutFolders(5));
- }
-
- @Test
- public void dailyCronologRollover() throws Exception {
- slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN);
- doRollover(randomOutputDir + "/%d{" + DAILY_CROLOLOG_DATE_PATTERN
- + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3);
- int expectedDirMin = 9 + slashCount;
- int expectDirMax = expectedDirMin + 1 + 1; // plus 1 of stepping into a
- // new month, and another 1 into
- // a new year
- expectedFileAndDirCount(9, expectedDirMin, expectDirMax);
- }
-
- @Test
- public void dailySizeBasedRollover() throws Exception {
- SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
- sizeAndTimeBasedFNATP.setMaxFileSize("10000");
- tbfnatp = sizeAndTimeBasedFNATP;
-
- slashCount = computeSlashCount(DAILY_DATE_PATTERN);
- doRollover(
- randomOutputDir + "/%d{" + 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
- // rollover occurs on the last period, that the last period is still
- // accounted
- // for
- checkPatternCompliance(5 + 1 + slashCount,
- "\\d{4}-\\d{2}-\\d{2}-clean(\\.\\d)(.zip)?");
- }
-
- @Test
- public void dailyChronologSizeBasedRollover() throws Exception {
- SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
- sizeAndTimeBasedFNATP.setMaxFileSize("10000");
- tbfnatp = sizeAndTimeBasedFNATP;
-
- slashCount = 1;
- doRollover(
- randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip",
- MILLIS_IN_DAY, 5, 5 * 4);
- checkDirPatternCompliance(6);
- }
-
-
- @Ignore
- @Test
- public void dailyChronologSizeBasedRolloverWhenLogFilenameDoesNotContainDirectory() throws Exception {
- SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
- sizeAndTimeBasedFNATP.setMaxFileSize("10000");
- tbfnatp = sizeAndTimeBasedFNATP;
-
- slashCount = 1;
- doRollover(
- "clean.%d{" + DAILY_DATE_PATTERN + "}.%i.zip",
- MILLIS_IN_DAY, 5, 5 * 4);
- checkDirPatternCompliance(6);
- }
-
- void doRollover(String fileNamePattern, long periodDurationInMillis,
- int maxHistory, int simulatedNumberOfPeriods) throws Exception {
- long currentTime = System.currentTimeMillis();
-
- RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
- rfa.setContext(context);
- rfa.setEncoder(encoder);
- // rfa.setFile(Constants.OUTPUT_DIR_PREFIX + "clean.txt");
- TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy<Object>();
- tbrp.setContext(context);
- tbrp.setFileNamePattern(fileNamePattern);
-
- tbrp.setMaxHistory(maxHistory);
- tbrp.setParent(rfa);
- tbrp.timeBasedFileNamingAndTriggeringPolicy = tbfnatp;
- tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
- tbrp.start();
- rfa.setRollingPolicy(tbrp);
- rfa.start();
-
- // lots of ticks per period
- int ticksPerPeriod = 512;
- long runLength = simulatedNumberOfPeriods * ticksPerPeriod;
-
- for (long i = 0; i < runLength; i++) {
- rfa
- .doAppend("Hello ----------------------------------------------------------"
- + i);
- tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(addTime(tbrp.timeBasedFileNamingAndTriggeringPolicy
- .getCurrentTime(), periodDurationInMillis / ticksPerPeriod));
-
- // wait every now and then for the compression job
- // otherwise, we might rollover a file for a given period before a previous
- // period's compressor had a chance to run
- if(i % (ticksPerPeriod/2) == 0) {
- waitForCompression(tbrp);
- }
- }
- waitForCompression(tbrp);
- rfa.stop();
- }
-
- void waitForCompression(TimeBasedRollingPolicy<Object> tbrp)
- throws InterruptedException, ExecutionException, TimeoutException {
- if (tbrp.future != null && !tbrp.future.isDone()) {
- tbrp.future.get(800, TimeUnit.MILLISECONDS);
- }
- }
-
- void findAllFoldersRecursively(File dir, List<File> fileList) {
- if (dir.isDirectory()) {
- File[] match = dir.listFiles(new FileFilter() {
- public boolean accept(File f) {
- return (f.isDirectory());
- }
- });
- for (File f : match) {
- fileList.add(f);
- findAllFoldersRecursively(f, fileList);
- }
- }
- }
-
- void findAllInFolderRecursivelyByStringContains(File dir,
- List<File> fileList, final String pattern) {
- if (dir.isDirectory()) {
- File[] match = dir.listFiles(new FileFilter() {
- public boolean accept(File f) {
- return (f.isDirectory() || f.getName().contains(pattern));
- }
- });
- for (File f : match) {
- fileList.add(f);
- if (f.isDirectory()) {
- findAllInFolderRecursivelyByStringContains(f, fileList, pattern);
- }
- }
- }
- }
-
- void findFilesInFolderRecursivelyByPatterMatch(File dir, List<File> fileList,
- final String pattern) {
- if (dir.isDirectory()) {
- File[] match = dir.listFiles(new FileFilter() {
- public boolean accept(File f) {
- return (f.isDirectory() || f.getName().matches(pattern));
- }
- });
- for (File f : match) {
- if (f.isDirectory()) {
- findFilesInFolderRecursivelyByPatterMatch(f, fileList, pattern);
- } else {
- fileList.add(f);
- }
- }
- }
- }
-
- void findFoldersInFolderRecursively(File dir, List<File> fileList) {
- if (dir.isDirectory()) {
- File[] match = dir.listFiles(new FileFilter() {
- public boolean accept(File f) {
- return f.isDirectory();
- }
- });
- for (File f : match) {
- fileList.add(f);
- findFoldersInFolderRecursively(f, fileList);
- }
- }
- }
-
- int expectedCountWithoutFolders(int maxHistory) {
- // maxHistory plus the currently active file
- return maxHistory + 1;
- }
-
- // sometimes, after a number of periods, there is an extra folder
- // from the previous "era" because the latest period - maxHistory, enters the
- // bound of the previous era. For example, with a maxHistory of 2, on 2009-09,
- // after 40 periods, the current period is 2013-01. Going back two months, the
- // year is 2012, and not 2013 (the current year).
- boolean extraFolder(int numPeriods, int periodsPerEra, int beginPeriod,
- int maxHistory) {
- // beginPeriod is 0 for JAN, 1 for FEB etc
- int valueOfLastMonth = ((beginPeriod) + numPeriods) % periodsPerEra;
- return (valueOfLastMonth < maxHistory);
- }
-
- int expectedCountWithFolders(int maxHistory, boolean extraFolder) {
- // each slash adds a new directory
- // + one file and one directory per archived log file
- int result = (maxHistory + 1) * 2 + slashCount;
- if (extraFolder)
- result++;
- return result;
- }
-
- void check(int expectedCount) {
- File dir = new File(randomOutputDir);
- List<File> fileList = new ArrayList<File>();
- findAllInFolderRecursivelyByStringContains(dir, fileList, "clean");
- assertEquals(expectedCount, fileList.size());
- }
-
- void expectedFileAndDirCount(int expectedFileAndDirCount,
- int expectedDirCountMin, int expectedDirCountMax) {
- File dir = new File(randomOutputDir);
- List<File> fileList = new ArrayList<File>();
- findFilesInFolderRecursivelyByPatterMatch(dir, fileList, "clean");
-
- List<File> dirList = new ArrayList<File>();
- findAllFoldersRecursively(dir, dirList);
- assertTrue("expectedDirCountMin=" + expectedDirCountMin
- + ", expectedDirCountMax=" + expectedDirCountMax + " actual value="
- + dirList.size(), expectedDirCountMin <= dirList.size()
- && dirList.size() <= expectedDirCountMax);
- }
-
- void checkPatternCompliance(int expectedClassCount, String regex) {
- File dir = new File(randomOutputDir);
- List<File> fileList = new ArrayList<File>();
- findFilesInFolderRecursivelyByPatterMatch(dir, fileList, regex);
- Set<String> set = groupByClass(fileList, regex);
- assertEquals(expectedClassCount, set.size());
- }
-
- void checkDirPatternCompliance(int expectedClassCount) {
- File dir = new File(randomOutputDir);
- List<File> fileList = new ArrayList<File>();
- findFoldersInFolderRecursively(dir, fileList);
- for (File f : fileList) {
- assertTrue(f.list().length >= 1);
- }
- assertEquals(expectedClassCount, fileList.size());
- }
-
- // reduce file names differing by index number into the same group
- // for example, 2009-11-01-clean.0.zip, 2009-11-01-clean.1.zip and
- // 2009-11-01-clean-2 are reduced into the same string (group)
- // 2009-11-01-clean
- Set<String> groupByClass(List<File> fileList, String regex) {
- Pattern p = Pattern.compile(regex);
- Set<String> set = new HashSet<String>();
- for (File f : fileList) {
- String n = f.getName();
- Matcher m = p.matcher(n);
- m.matches();
- int begin = m.start(1);
- String reduced = n.substring(0, begin);
- set.add(reduced);
- }
- System.out.println(set);
- return set;
- }
-
- static long addTime(long currentTime, long timeToWait) {
- return currentTime + timeToWait;
- }
-
-}
diff --git a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
index a1e99a6..a428f45 100644
--- a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
+++ b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala
@@ -28,23 +28,29 @@ class TimeBasedRollingWithArchiveRemoval_STest {
var encoder: EchoEncoder[AnyRef] = new EchoEncoder[AnyRef]
val MONTHLY_DATE_PATTERN: String = "yyyy-MM"
- val MONTHLY_CROLOLOG_DATE_PATTERN: String = "yyyy/MM"
- final val DAILY_CROLOLOG_DATE_PATTERN: String = "yyyy/MM/dd"
+
+ val MONTHLY_CRONOLOG_DATE_PATTERN: String = "yyyy/MM"
+ final val DAILY_CRONOLOG_DATE_PATTERN: String = "yyyy/MM/dd"
val MILLIS_IN_MINUTE: Long = 60 * 1000
val MILLIS_IN_HOUR: Long = 60 * MILLIS_IN_MINUTE
val MILLIS_IN_DAY: Long = 24 * MILLIS_IN_HOUR
val MILLIS_IN_MONTH: Long = ((365.0 / 12) * MILLIS_IN_DAY).asInstanceOf[Long]
- var diff: Int = RandomUtil.getPositiveInt
- var randomOutputDir: String = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/"
+ var diff: Int = _
+ var randomOutputDir: String = _
var slashCount: Int = 0
// by default tbfnatp is an instance of DefaultTimeBasedFileNamingAndTriggeringPolicy
var tbfnatp: TimeBasedFileNamingAndTriggeringPolicy[AnyRef] = new DefaultTimeBasedFileNamingAndTriggeringPolicy[AnyRef]
+ val now = System.currentTimeMillis
+
+
@Before def setUp {
context.setName("test")
+ diff = RandomUtil.getPositiveInt
+ randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/"
}
def computeSlashCount(datePattern: String): Int = {
@@ -52,20 +58,29 @@ class TimeBasedRollingWithArchiveRemoval_STest {
else datePattern.foldLeft(0)((count, c) => if (c == '/') count + 1 else count)
}
+ def genMontlyRollover(maxHistory: Int, simulatedNumberOfPeriods: Int, startInactivity: Int, numInactivityPeriods: Int) {
+ slashCount = computeSlashCount(MONTHLY_DATE_PATTERN)
+ doRollover(now, randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt", MILLIS_IN_MONTH, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods)
+ check(expectedCountWithoutFolders(maxHistory))
+ }
+
@Test
def montlyRollover {
- slashCount = computeSlashCount(MONTHLY_DATE_PATTERN)
- doRollover(randomOutputDir + "clean-%d{" + MONTHLY_DATE_PATTERN + "}.txt", MILLIS_IN_MONTH, 20, 20 * 3)
- check(expectedCountWithoutFolders(20))
+ genMontlyRollover(maxHistory = 20, simulatedNumberOfPeriods = 20 * 3, startInactivity = 0, numInactivityPeriods = 0)
+ setUp
+ genMontlyRollover(maxHistory = 6, simulatedNumberOfPeriods = 70, startInactivity = 30, numInactivityPeriods = 1)
+ setUp
+ genMontlyRollover(maxHistory = 6, simulatedNumberOfPeriods = 10, startInactivity = 3, numInactivityPeriods = 4)
+
}
@Test def monthlyRolloverOverManyPeriods {
System.out.println("randomOutputDir=" + randomOutputDir)
- slashCount = computeSlashCount(MONTHLY_CROLOLOG_DATE_PATTERN)
+ slashCount = computeSlashCount(MONTHLY_CRONOLOG_DATE_PATTERN)
var numPeriods: Int = 40
var maxHistory: Int = 2
- val (startTime, endTime) = doRollover(randomOutputDir + "/%d{" + MONTHLY_CROLOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_MONTH, maxHistory, numPeriods)
+ val (startTime, endTime) = doRollover(now, randomOutputDir + "/%d{" + MONTHLY_CRONOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_MONTH, maxHistory, numPeriods)
val differenceInMonths = RollingCalendar.diffInMonths(startTime, endTime)
var indexOfStartPeriod: Int = Calendar.getInstance.get(Calendar.MONTH)
val withExtraFolder = extraFolder(differenceInMonths, 12, indexOfStartPeriod, maxHistory)
@@ -75,16 +90,28 @@ class TimeBasedRollingWithArchiveRemoval_STest {
@Test def dailyRollover {
slashCount = computeSlashCount(DAILY_DATE_PATTERN)
- doRollover(randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip", MILLIS_IN_DAY, 5, 5 * 3)
+ doRollover(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt.zip", MILLIS_IN_DAY, 5, 5 * 3, startInactivity = 6, numInactivityPeriods = 3)
+ StatusPrinter.print(context)
check(expectedCountWithoutFolders(5))
}
+ @Test def dailyRolloverWithSecondPhase {
+ slashCount = computeSlashCount(DAILY_DATE_PATTERN)
+ val maxHistory = 5
+ val simulatedNumberOfPeriods = maxHistory * 2
+ val (startTime, endTime) = doRollover(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory * 2)
+ doRollover(endTime + MILLIS_IN_DAY * 10, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory)
+ check(expectedCountWithoutFolders(maxHistory))
+ }
+
+
@Test def dailyCronologRollover {
- slashCount = computeSlashCount(DAILY_CROLOLOG_DATE_PATTERN)
- doRollover(randomOutputDir + "/%d{" + DAILY_CROLOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3)
+ slashCount = computeSlashCount(DAILY_CRONOLOG_DATE_PATTERN)
+ doRollover(now, randomOutputDir + "/%d{" + DAILY_CRONOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3)
var expectedDirMin: Int = 9 + slashCount
var expectDirMax: Int = expectedDirMin + 1 + 1
expectedFileAndDirCount(9, expectedDirMin, expectDirMax)
+
}
@Test def dailySizeBasedRollover {
@@ -92,7 +119,7 @@ class TimeBasedRollingWithArchiveRemoval_STest {
sizeAndTimeBasedFNATP.setMaxFileSize("10000")
tbfnatp = sizeAndTimeBasedFNATP
slashCount = computeSlashCount(DAILY_DATE_PATTERN)
- doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
+ doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
checkPatternCompliance(5 + 1 + slashCount, "\\d{4}-\\d{2}-\\d{2}-clean(\\.\\d)(.zip)?")
}
@@ -101,10 +128,22 @@ class TimeBasedRollingWithArchiveRemoval_STest {
sizeAndTimeBasedFNATP.setMaxFileSize("10000")
tbfnatp = sizeAndTimeBasedFNATP
slashCount = 1
- doRollover(randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
+ doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
checkDirPatternCompliance(6)
}
+ @Test def dailyChronologSizeBasedRolloverWithSecondPhase {
+ var sizeAndTimeBasedFNATP: SizeAndTimeBasedFNATP[AnyRef] = new SizeAndTimeBasedFNATP[AnyRef]
+ sizeAndTimeBasedFNATP.setMaxFileSize("10000")
+ tbfnatp = sizeAndTimeBasedFNATP
+ slashCount = 1
+ val maxHistory = 5
+ val simulatedNumberOfPeriods = maxHistory * 4
+ val (startTime, endTime) = doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, 3)
+ doRollover(endTime+MILLIS_IN_DAY*7, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods)
+ checkDirPatternCompliance(maxHistory+1)
+ }
+
// this test requires changing the current working directory which is impossible in Java
@Ignore
@@ -113,7 +152,7 @@ class TimeBasedRollingWithArchiveRemoval_STest {
sizeAndTimeBasedFNATP.setMaxFileSize("10000")
tbfnatp = sizeAndTimeBasedFNATP
slashCount = 1
- doRollover("clean.%d{" + DAILY_DATE_PATTERN + "}.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
+ doRollover(now, "clean.%d{" + DAILY_DATE_PATTERN + "}.%i.zip", MILLIS_IN_DAY, 5, 5 * 4)
checkDirPatternCompliance(6)
}
@@ -124,7 +163,7 @@ class TimeBasedRollingWithArchiveRemoval_STest {
def expectedCountWithFolders(maxHistory: Int, extraFolder: Boolean): Int = {
val numLogFiles = (maxHistory + 1)
- val numLogFilesAndFolders = numLogFiles*2
+ val numLogFilesAndFolders = numLogFiles * 2
var result: Int = numLogFilesAndFolders + slashCount
if (extraFolder) result += 1
result
@@ -140,8 +179,7 @@ class TimeBasedRollingWithArchiveRemoval_STest {
}
}
- def doRollover(fileNamePattern: String, periodDurationInMillis: Long, maxHistory: Int, simulatedNumberOfPeriods: Int): (Long, Long) = {
- var currentTime: Long = System.currentTimeMillis
+ def doRollover(currentTime: Long, fileNamePattern: String, periodDurationInMillis: Long, maxHistory: Int, simulatedNumberOfPeriods: Int, startInactivity: Int = 0, numInactivityPeriods: Int = 0): (Long, Long) = {
val startTime = currentTime
var rfa: RollingFileAppender[AnyRef] = new RollingFileAppender[AnyRef]
rfa.setContext(context)
@@ -158,15 +196,20 @@ class TimeBasedRollingWithArchiveRemoval_STest {
rfa.start
var ticksPerPeriod: Int = 512
var runLength = simulatedNumberOfPeriods * ticksPerPeriod
+ val startInactivityIndex: Int = 1 + startInactivity * ticksPerPeriod
+ val endInactivityIndex = startInactivity + numInactivityPeriods * ticksPerPeriod
+
for (i <- 0 to runLength) {
- rfa.doAppend("Hello ----------------------------------------------------------" + i)
+ if (i < startInactivityIndex || i > endInactivityIndex) {
+ rfa.doAppend("Hello ----------------------------------------------------------" + i)
+ }
tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(addTime(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime, periodDurationInMillis / ticksPerPeriod))
if (i % (ticksPerPeriod / 2) == 0) {
waitForCompression(tbrp)
}
-
}
+
waitForCompression(tbrp)
rfa.stop
(startTime, tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime)
-----------------------------------------------------------------------
Summary of changes:
.../classic/spi/PackagingDataCalculator.java | 2 +-
.../core/rolling/SizeAndTimeBasedFNATP.java | 2 +-
.../core/rolling/helper/DefaultArchiveRemover.java | 47 ++-
.../core/rolling/helper/FileFilterUtil.java | 2 +-
.../core/rolling/helper/RollingCalendar.java | 14 +-
.../helper/SizeAndTimeBasedArchiveRemover.java | 9 +-
.../rolling/helper/TimeBasedArchiveRemover.java | 16 +-
.../TimeBasedRollingWithArchiveRemovalTest.java | 391 --------------------
.../TimeBasedRollingWithArchiveRemoval_STest.scala | 83 ++++-
9 files changed, 120 insertions(+), 446 deletions(-)
delete mode 100644 logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
1
0
performance issue
-----------------
Key: LBCLASSIC-291
URL: http://jira.qos.ch/browse/LBCLASSIC-291
Project: logback-classic
Issue Type: Improvement
Components: Other
Affects Versions: 0.9.29
Reporter: Roman Kosenko
Assignee: Logback dev list
http://logback.qos.ch/manual/encoders.html says:
Below is an excerpt from the LayoutWrappingEncoder class illustrating how delegation to the wrapped layout instance is done.
package ch.qos.logback.core.encoder;
public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
protected Layout<E> layout;
private Charset charset;
public void doEncode(E event) throws IOException {
String txt = layout.doLayout(event);
outputStream.write(convertToBytes(txt));
outputStream.flush();
}
private byte[] convertToBytes(String s) {
if (charset == null) {
return s.getBytes();
} else {
return s.getBytes(charset);
}
}
}
Let's leave fact that this source is uncompilable...
But in real source of ch.qos.logback.core.encoder.LayoutWrappingEncoder we can see another code. Method convertToBytes contains line: "return s.getBytes(charset.name());".
So real variant isn't so fast as one in example - you get the name of your java.nio.charset.Charset and then String.getBytes make lookup by this name to get Charset instance again. And this is doing for every log message.
P.S. I know, that String.getBytes(Charset) is available from Java 6 only. But it released in 2006 and current version is 7. If you want to support very old version of jre maybe is it better to separate versions like this is doing in other libraries? Another variant is direct using of CharsetEncoder.
--
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