slf4j-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
- 2607 discussions

[Bug 70] " logging a stack trace along with a parameterized string" solution proposal
by bugzilla-daemon@pixie.qos.ch 21 Apr '10
by bugzilla-daemon@pixie.qos.ch 21 Apr '10
21 Apr '10
http://bugzilla.slf4j.org/show_bug.cgi?id=70
Ceki Gulcu <listid(a)qos.ch> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #17 from Ceki Gulcu <listid(a)qos.ch> 2010-04-21 18:45:27 ---
Fixed in http://github.com/ceki/slf4j/commit/35ca85dfaa1c293
Joern's patch was applied with a modification. The Result class has been
renamed FormattingTuple. The getArgArray() method returns a trimmed array if a
throwable was indeed its last element.
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
1
0

[GIT] SLF4J: Simple Logging Facade for Java branch, master, updated. v1.5.11-18-g35ca85d
by git-noreply@pixie.qos.ch 21 Apr '10
by git-noreply@pixie.qos.ch 21 Apr '10
21 Apr '10
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 "SLF4J: Simple Logging Facade for Java".
The branch, master has been updated
via 35ca85dfaa1c2933619f9eeef86c907223b55a96 (commit)
from 775c6a59df22c048231b8ba31995e4ef79311663 (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=slf4j.git;a=commit;h=35ca85dfaa1c2933619f9eeef8…
http://github.com/ceki/slf4j/commit/35ca85dfaa1c2933619f9eeef86c907223b55a96
commit 35ca85dfaa1c2933619f9eeef86c907223b55a96
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Wed Apr 21 17:18:25 2010 +0200
- minor editing in MessageFormatterPerfTest
- added blurb about bug 70
diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
index fbec292..5077c57 100644
--- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
+++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
@@ -36,9 +36,15 @@ public class MessageFormatterPerfTest extends TestCase {
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
}
+ public void testSLF4JPerf_TwoArg() {
+ slf4jMessageFormatter_TwoArg(RUN_LENGTH);
+ double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
+ long referencePerf = 60;
+ BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
+ }
+
+
public double slf4jMessageFormatter_OneArg(long len) {
- String s = "";
- s += ""; // keep compiler happy
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
final FormattingTuple tp = MessageFormatter.format("This is some rather short message {} ", i1);
@@ -52,14 +58,6 @@ public class MessageFormatterPerfTest extends TestCase {
return (end - start)/(1000*1000.0);
}
- public void testSLF4JPerf_TwoArg() {
- slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- System.out.println("duration2=" + duration);
- long referencePerf = 60;
- BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
- }
-
public double slf4jMessageFormatter_TwoArg(long len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
diff --git a/slf4j-site/src/site/pages/news.html b/slf4j-site/src/site/pages/news.html
index 24b0b39..796b504 100644
--- a/slf4j-site/src/site/pages/news.html
+++ b/slf4j-site/src/site/pages/news.html
@@ -6,9 +6,11 @@
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>SLF4J News</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/site.css" />
+ <link rel="stylesheet" type="text/css" href="css/prettify.css" />
</head>
- <body>
+ <body onload="prettyPrint()">
<script type="text/javascript">prefix='';</script>
+ <script type="text/javascript" src="js/prettify.js"></script>
<script src="templates/header.js" type="text/javascript"></script>
<div id="left">
@@ -34,6 +36,36 @@
series is expected to require JDK 1.5 or later.
</p>
+ <p>Note that as of SLF4J version 1.6.0, in the absence of an SLF4J
+ binding, slf4j-api will default to a no-operation implementation
+ discarding all log requests. Thus, instead of throwing an
+ exception, SLF4J will emit a single warning message about the
+ absence of a binding and proceed to discard all log requests
+ without further protest.
+ </p>
+
+ <p>In the presence of multiple parameters and if the last argument
+ in a logging statement is an exception or more precisely of type
+ <code>java.lang.Throwable</code>, then SLF4J will now presume that
+ the user wants the last argument to be treated as an exception and
+ not a simple parameters. For example, in the following catch
+ clause:
+ </p>
+
+ <pre class="prettyprint">try {
+ ..
+ } catch(IOException e) {
+ logger.error("Failed connect to {}", hostname, e);
+ }</pre>
+
+ <p>the <code>IOException</code> 'e' will now be treated as an
+ exception and have its stack trace printed out. In previous
+ versions of SLF4J, the exception was treated as an unused
+ parameter. This fixes <a
+ href="http://bugzilla.slf4j.org/show_bug.cgi?id=70">bug 70</a>
+ submitted by Joern Huxhorn who also provided the relevant patch.
+ </p>
+
<p>The <code>log</code> method in <code>LocationAwareLogger</code>
interface now admits an additional parameter of type
<code>Object[]</code> representing additional arguments of the log
@@ -42,13 +74,6 @@
with 1.6.x must be used.
</p>
- <p>Note that as of SLF4J version 1.6.0, in the absence of an SLF4J
- binding, slf4j-api will default to a no-operation implementation
- discarding all log requests. Thus, instead of throwing an
- exception, SLF4J will emit a single warning message about the
- absence of a binding and proceed to discard all log requests
- without further protest.
- </p>
<p>Fixed <a
href="http://bugzilla.slf4j.org/show_bug.cgi?id=150">bug 150</a> by
-----------------------------------------------------------------------
Summary of changes:
.../slf4j/helpers/MessageFormatterPerfTest.java | 18 ++++-----
slf4j-site/src/site/pages/news.html | 41 ++++++++++++++++----
2 files changed, 41 insertions(+), 18 deletions(-)
hooks/post-receive
--
SLF4J: Simple Logging Facade for Java
1
0

[GIT] SLF4J: Simple Logging Facade for Java branch, master, updated. v1.5.11-17-g775c6a5
by git-noreply@pixie.qos.ch 21 Apr '10
by git-noreply@pixie.qos.ch 21 Apr '10
21 Apr '10
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 "SLF4J: Simple Logging Facade for Java".
The branch, master has been updated
via 775c6a59df22c048231b8ba31995e4ef79311663 (commit)
via 7be32abc9f7b0eeaa47017c8b7c6800c140222e5 (commit)
via eb4d4944ea655ea47d9491a6e340e98a5bcd995c (commit)
via 09b2354f7f22d732ea4013aaa9efd4839296c007 (commit)
via fd74fb61746d10021f4e33b0c3cd1543a89ffc0c (commit)
via 3c0ab3466b6fa6e915974c72558d64c570734700 (commit)
from 6dd2bd58cffc857d064d0e0ac3017d6aee924bb8 (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=slf4j.git;a=commit;h=775c6a59df22c048231b8ba319…
http://github.com/ceki/slf4j/commit/775c6a59df22c048231b8ba31995e4ef79311663
commit 775c6a59df22c048231b8ba31995e4ef79311663
Merge: 09b2354 7be32ab
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Wed Apr 21 17:16:06 2010 +0200
Merge branch 'bug70'
Conflicts:
slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
diff --cc slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
index 583cc7b,5bfee77..fbec292
--- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
+++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
@@@ -35,36 -36,42 +36,45 @@@ public class MessageFormatterPerfTest e
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
}
-
- public void testSLF4JPerf_TwoArg() {
- slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- long referencePerf = 60;
- BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
- }
-
- public void testSLF4JPerf_TwoArg() {
- slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
- System.out.println("duration2=" + duration);
- long referencePerf = 60;
- BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
- }
-
public double slf4jMessageFormatter_OneArg(long len) {
+ String s = "";
+ s += ""; // keep compiler happy
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
- s = MessageFormatter.format("This is some rather short message {} ", i1);
- final FormattingTuple tp = MessageFormatter.format(
- "This is some rather short message {} ", i1);
++ final FormattingTuple tp = MessageFormatter.format("This is some rather short message {} ", i1);
+ tp.getMessage();
+ tp.getArgArray();
+ tp.getThrowable();
++
++ MessageFormatter.format("This is some rather short message {} ", i1);
}
long end = System.nanoTime();
- return (end - start) / (1000 * 1000.0);
+ return (end - start)/(1000*1000.0);
+ }
++
++ public void testSLF4JPerf_TwoArg() {
++ slf4jMessageFormatter_TwoArg(RUN_LENGTH);
++ double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
++ System.out.println("duration2=" + duration);
++ long referencePerf = 60;
++ BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
+ }
public double slf4jMessageFormatter_TwoArg(long len) {
-- String s = "";
-- s += ""; // keep compiler happy
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
- s = MessageFormatter.format("This is some {} short message {} ", i1, i2);
+ final FormattingTuple tp = MessageFormatter.format(
+ "This is some {} short message {} ", i1, i2);
+ tp.getMessage();
+ tp.getArgArray();
+ tp.getThrowable();
}
long end = System.nanoTime();
- return (end - start) / (1000 * 1000.0);
+ return (end - start)/(1000*1000.0);
}
-
+
++
++
public double jdkMessageFormatter(long len) {
String s = "";
s += ""; // keep compiler happy
http://git.qos.ch/gitweb/?p=slf4j.git;a=commit;h=09b2354f7f22d732ea4013aaa9…
http://github.com/ceki/slf4j/commit/09b2354f7f22d732ea4013aaa9efd4839296c007
commit 09b2354f7f22d732ea4013aaa9efd4839296c007
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Wed Apr 21 16:28:31 2010 +0200
added a two arg test
diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
index 3c6f236..583cc7b 100644
--- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
+++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
@@ -7,9 +7,11 @@ import junit.framework.TestCase;
public class MessageFormatterPerfTest extends TestCase {
Integer i1 = new Integer(1);
+ Integer i2 = new Integer(2);
static long RUN_LENGTH = 100000;
- static long REFERENCE_BIPS = 9000;
-
+ //
+ static long REFERENCE_BIPS = 48416;
+
public MessageFormatterPerfTest(String name) {
super(name);
}
@@ -23,36 +25,56 @@ public class MessageFormatterPerfTest extends TestCase {
public void XtestJDKFormatterPerf() {
jdkMessageFormatter(RUN_LENGTH);
double duration = jdkMessageFormatter(RUN_LENGTH);
- System.out.println("jdk duration = "+duration+" nanos");
+ System.out.println("jdk duration = " + duration + " nanos");
+ }
+
+ public void testSLF4JPerf_OneArg() {
+ slf4jMessageFormatter_OneArg(RUN_LENGTH);
+ double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH);
+ long referencePerf = 36;
+ BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
}
+
- public void testSLF4JPerf() {
- slf4jMessageFormatter(RUN_LENGTH);
- double duration = slf4jMessageFormatter(RUN_LENGTH);
- long referencePerf = 140;
+ public void testSLF4JPerf_TwoArg() {
+ slf4jMessageFormatter_TwoArg(RUN_LENGTH);
+ double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
+ long referencePerf = 60;
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
}
- public double slf4jMessageFormatter(long len) {
- String s = "";
+ public double slf4jMessageFormatter_OneArg(long len) {
+ String s = "";
s += ""; // keep compiler happy
- long start = System.currentTimeMillis();
+ long start = System.nanoTime();
for (int i = 0; i < len; i++) {
s = MessageFormatter.format("This is some rather short message {} ", i1);
}
- long end = System.currentTimeMillis();
- return (1.0*end - start);
- }
+ long end = System.nanoTime();
+ return (end - start)/(1000*1000.0);
+ }
+
+ public double slf4jMessageFormatter_TwoArg(long len) {
+ String s = "";
+ s += ""; // keep compiler happy
+ long start = System.nanoTime();
+ for (int i = 0; i < len; i++) {
+ s = MessageFormatter.format("This is some {} short message {} ", i1, i2);
+ }
+ long end = System.nanoTime();
+ return (end - start)/(1000*1000.0);
+ }
+
public double jdkMessageFormatter(long len) {
- String s = "";
+ String s = "";
s += ""; // keep compiler happy
long start = System.currentTimeMillis();
- Object[] oa = new Object[] {i1};
+ Object[] oa = new Object[] { i1 };
for (int i = 0; i < len; i++) {
s = MessageFormat.format("This is some rather short message {0}", oa);
}
long end = System.currentTimeMillis();
- return (1.0*end - start);
+ return (1.0 * end - start);
}
}
-----------------------------------------------------------------------
Summary of changes:
.../java/org/slf4j/helpers/FormattingTuple.java | 74 +++
.../java/org/slf4j/helpers/MessageFormatter.java | 51 ++-
.../slf4j/helpers/MessageFormatterPerfTest.java | 70 ++-
.../org/slf4j/helpers/MessageFormatterTest.java | 150 +++---
.../src/main/java/org/slf4j/ext/LoggerWrapper.java | 99 +++--
slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java | 12 +-
.../org/slf4j/instrumentation/LogTransformer.java | 535 ++++++++++----------
.../main/java/org/slf4j/impl/JCLLoggerAdapter.java | 62 ++--
.../java/org/slf4j/impl/JDK14LoggerAdapter.java | 61 ++--
.../java/org/slf4j/impl/Log4jLoggerAdapter.java | 64 ++--
.../src/main/java/org/slf4j/impl/SimpleLogger.java | 84 ++--
11 files changed, 723 insertions(+), 539 deletions(-)
create mode 100644 slf4j-api/src/main/java/org/slf4j/helpers/FormattingTuple.java
hooks/post-receive
--
SLF4J: Simple Logging Facade for Java
1
0

[GIT] SLF4J: Simple Logging Facade for Java branch, bug70, updated. v1.5.11-15-g7be32ab
by git-noreply@pixie.qos.ch 21 Apr '10
by git-noreply@pixie.qos.ch 21 Apr '10
21 Apr '10
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 "SLF4J: Simple Logging Facade for Java".
The branch, bug70 has been updated
via 7be32abc9f7b0eeaa47017c8b7c6800c140222e5 (commit)
via eb4d4944ea655ea47d9491a6e340e98a5bcd995c (commit)
via fd74fb61746d10021f4e33b0c3cd1543a89ffc0c (commit)
from 3c0ab3466b6fa6e915974c72558d64c570734700 (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 -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
.../java/org/slf4j/helpers/FormattingTuple.java | 26 +++++++++-
.../java/org/slf4j/helpers/MessageFormatter.java | 29 ++++++-----
.../slf4j/helpers/MessageFormatterPerfTest.java | 51 +++++++++++++++-----
.../src/main/java/org/slf4j/ext/LoggerWrapper.java | 21 ++++----
4 files changed, 89 insertions(+), 38 deletions(-)
hooks/post-receive
--
SLF4J: Simple Logging Facade for Java
1
0

15 Apr '10
http://bugzilla.slf4j.org/show_bug.cgi?id=138
Martin Serrano <martin(a)attivio.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |martin(a)attivio.com
--- Comment #17 from Martin Serrano <martin(a)attivio.com> 2010-04-15 20:27:18 ---
FYI: I have run into this same issue using ANT and its associated classloader
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
1
0
Hi,
I want to use slf4j in Eclipse RCP Projects.
My idea is to replace
Activator.getDefault().getLog().log( new Status( IStatus.INFO,
Activator.PLUGIN_ID, msg ) );
into
class My {
static Logger logger = LoggerFactory.getLogger(My.class);
something() {
logger.info(msg);
}
}
But there is a problem, I need the Bundle to use the eclipse logging. It
is possible to get the Bundle from the class objects.
But the ILoggerFactory interface has only a getLogger( String ) method :-(
And the LoggerFactory.getLogger( Class ) methods calls getLogger(
c.getName ).
I think it should be possible to log the Bundle in osgi containers. Is
there any solution ?
My idea,
create an
interface ILoggerFactory2 extends ILoggerFactory {
Logger getLogger( Class c );
}
Regrads,
André
--
_____________________________________________________
André Kullmann
Otto Group · GroupTechnologyPartner - Dresden (GTP)
Anwendungsentwickler · Touchpoints und Kunde · FI-IM-TK
_______________________________________________
GroupTechnologyPartner - Dresden · Freiberger Straße 35 · 01067 Dresden
Telefon +49 (0) 351 497 23 185 · Fax +49 (0) 351 497 23 119
andre.kullmann(a)osp-dd.de · www.ottogroup.com
_______________________________________________
AG Dresden, HRB 2475 Geschäftsführer: Dr. Thomas Tribius, Martin Mildner
3
2

[Bug 70] " logging a stack trace along with a parameterized string" solution proposal
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
09 Apr '10
http://bugzilla.slf4j.org/show_bug.cgi?id=70
--- Comment #16 from Ceki Gulcu <lists(a)slf4j.org> 2010-04-09 13:08:20 ---
Applied the fix provided by Joern in
http://github.com/ceki/slf4j/commit/3c0ab3466b6fa6e915974c
As you judge from that commit, the change is pretty extensive.
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
1
0

[GIT] SLF4J: Simple Logging Facade for Java branch, bug70, created. v1.5.11-12-g3c0ab34
by git-noreply@pixie.qos.ch 09 Apr '10
by git-noreply@pixie.qos.ch 09 Apr '10
09 Apr '10
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 "SLF4J: Simple Logging Facade for Java".
The branch, bug70 has been created
at 3c0ab3466b6fa6e915974c72558d64c570734700 (commit)
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=slf4j.git;a=commit;h=3c0ab3466b6fa6e915974c7255…
http://github.com/ceki/slf4j/commit/3c0ab3466b6fa6e915974c72558d64c570734700
commit 3c0ab3466b6fa6e915974c72558d64c570734700
Author: Ceki Gulcu <ceki(a)qos.ch>
Date: Fri Apr 9 13:02:20 2010 +0200
Fixing bug 70
diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/FormattingTuple.java b/slf4j-api/src/main/java/org/slf4j/helpers/FormattingTuple.java
new file mode 100644
index 0000000..c202345
--- /dev/null
+++ b/slf4j-api/src/main/java/org/slf4j/helpers/FormattingTuple.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2004-2010 QOS.ch All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.slf4j.helpers;
+
+/**
+ * Holds the results of formatting done by {@link MessageFormatter}.
+ *
+ * @author Joern Huxhorn
+ */
+public class FormattingTuple {
+
+
+ static public FormattingTuple NULL = new FormattingTuple(null);
+
+ private String message;
+ private Throwable throwable;
+
+ public FormattingTuple(String message) {
+ this(message, null);
+ }
+
+ public FormattingTuple(String message, Throwable throwable) {
+ this.message = message;
+ this.throwable = throwable;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+}
diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
index 0f38864..e1c0bdf 100644
--- a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
+++ b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
@@ -64,13 +64,16 @@ import java.util.Map;
* character should be escaped. There is no need to escape the '}' character.
* For example,
*
- * <pre>MessageFormatter.format("Set \\{} is not equal to {}.", "1,2");</pre>
+ * <pre>
+ * MessageFormatter.format("Set \\{} is not equal to {}.", "1,2");
+ * </pre>
*
* will return the string "Set {} is not equal to 1,2.".
*
* <p>
* The escaping behavior just described can be overridden by escaping the escape
* character '\'. Calling
+ *
* <pre>
* MessageFormatter.format("File name is C:\\\\{}.", "file.zip");
* </pre>
@@ -90,9 +93,10 @@ import java.util.Map;
* {@link #arrayFormat(String, Object[])} methods for more details.
*
* @author Ceki Gülcü
+ * @author Joern Huxhorn
*/
final public class MessageFormatter {
- static final char DELIM_START = '{';
+ static final char DELIM_START = '{';
static final char DELIM_STOP = '}';
static final String DELIM_STR = "{}";
private static final char ESCAPE_CHAR = '\\';
@@ -116,7 +120,7 @@ final public class MessageFormatter {
* The argument to be substituted in place of the formatting anchor
* @return The formatted message
*/
- final public static String format(String messagePattern, Object arg) {
+ final public static FormattingTuple format(String messagePattern, Object arg) {
return arrayFormat(messagePattern, new Object[] { arg });
}
@@ -143,11 +147,23 @@ final public class MessageFormatter {
* anchor
* @return The formatted message
*/
- final public static String format(final String messagePattern, Object arg1,
+ final public static FormattingTuple format(final String messagePattern, Object arg1,
Object arg2) {
return arrayFormat(messagePattern, new Object[] { arg1, arg2 });
}
+ static final Throwable getThrowableCandidate(Object[] argArray) {
+ if (argArray == null || argArray.length == 0) {
+ return null;
+ }
+
+ final Object lastEntry = argArray[argArray.length - 1];
+ if(lastEntry instanceof Throwable) {
+ return (Throwable) lastEntry;
+ }
+ return null;
+ }
+
/**
* Same principle as the {@link #format(String, Object)} and
* {@link #format(String, Object, Object)} methods except that any number of
@@ -160,30 +176,36 @@ final public class MessageFormatter {
* anchors
* @return The formatted message
*/
- final public static String arrayFormat(final String messagePattern,
+ final public static FormattingTuple arrayFormat(final String messagePattern,
final Object[] argArray) {
+
+ Throwable throwableCandidate = getThrowableCandidate(argArray);
+
if (messagePattern == null) {
- return null;
+ return new FormattingTuple(null, throwableCandidate);
+
}
if (argArray == null) {
- return messagePattern;
+ return new FormattingTuple(messagePattern);
}
+
int i = 0;
int j;
StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50);
- for (int L = 0; L < argArray.length; L++) {
+ int L;
+ for (L = 0; L < argArray.length; L++) {
j = messagePattern.indexOf(DELIM_STR, i);
if (j == -1) {
// no more variables
if (i == 0) { // this is a simple string
- return messagePattern;
+ return new FormattingTuple(messagePattern, throwableCandidate);
} else { // add the tail string which contains no variables and return
// the result.
sbuf.append(messagePattern.substring(i, messagePattern.length()));
- return sbuf.toString();
+ return new FormattingTuple(sbuf.toString(), throwableCandidate);;
}
} else {
if (isEscapedDelimeter(messagePattern, j)) {
@@ -210,7 +232,11 @@ final public class MessageFormatter {
}
// append the characters following the last {} pair.
sbuf.append(messagePattern.substring(i, messagePattern.length()));
- return sbuf.toString();
+ if (L < argArray.length - 1) {
+ return new FormattingTuple(sbuf.toString(), throwableCandidate);
+ } else {
+ return new FormattingTuple(sbuf.toString());
+ }
}
final static boolean isEscapedDelimeter(String messagePattern,
diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
index 3c6f236..41e7355 100644
--- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
+++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterPerfTest.java
@@ -9,7 +9,7 @@ public class MessageFormatterPerfTest extends TestCase {
Integer i1 = new Integer(1);
static long RUN_LENGTH = 100000;
static long REFERENCE_BIPS = 9000;
-
+
public MessageFormatterPerfTest(String name) {
super(name);
}
@@ -23,9 +23,9 @@ public class MessageFormatterPerfTest extends TestCase {
public void XtestJDKFormatterPerf() {
jdkMessageFormatter(RUN_LENGTH);
double duration = jdkMessageFormatter(RUN_LENGTH);
- System.out.println("jdk duration = "+duration+" nanos");
+ System.out.println("jdk duration = " + duration + " nanos");
}
-
+
public void testSLF4JPerf() {
slf4jMessageFormatter(RUN_LENGTH);
double duration = slf4jMessageFormatter(RUN_LENGTH);
@@ -34,25 +34,27 @@ public class MessageFormatterPerfTest extends TestCase {
}
public double slf4jMessageFormatter(long len) {
- String s = "";
+ String s = "";
s += ""; // keep compiler happy
long start = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
- s = MessageFormatter.format("This is some rather short message {} ", i1);
+ s = MessageFormatter.format("This is some rather short message {} ", i1)
+ .getMessage();
}
long end = System.currentTimeMillis();
- return (1.0*end - start);
- }
+ return (1.0 * end - start);
+ }
+
public double jdkMessageFormatter(long len) {
- String s = "";
+ String s = "";
s += ""; // keep compiler happy
long start = System.currentTimeMillis();
- Object[] oa = new Object[] {i1};
+ Object[] oa = new Object[] { i1 };
for (int i = 0; i < len; i++) {
s = MessageFormat.format("This is some rather short message {0}", oa);
}
long end = System.currentTimeMillis();
- return (1.0*end - start);
+ return (1.0 * end - start);
}
}
diff --git a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java
index 829cd0f..0d3c587 100644
--- a/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java
+++ b/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java
@@ -47,121 +47,128 @@ public class MessageFormatterTest extends TestCase {
Integer[] ia0 = new Integer[] { i1, i2, i3 };
Integer[] ia1 = new Integer[] { new Integer(10), new Integer(20),
new Integer(30) };
-
+
String result;
-
-
+
public void testNull() {
- result = MessageFormatter.format(null, i1);
+ result = MessageFormatter.format(null, i1).getMessage();
assertEquals(null, result);
}
public void testNullParam() {
- result = MessageFormatter.format("Value is {}.", null);
+ result = MessageFormatter.format("Value is {}.", null).getMessage();
assertEquals("Value is null.", result);
- result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, null);
+ result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, null)
+ .getMessage();
assertEquals("Val1 is null, val2 is null.", result);
- result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1, null);
+ result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1, null)
+ .getMessage();
assertEquals("Val1 is 1, val2 is null.", result);
- result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, i2);
+ result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, i2)
+ .getMessage();
assertEquals("Val1 is null, val2 is 2.", result);
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
- new Integer[] { null, null, null });
+ new Integer[] { null, null, null }).getMessage();
assertEquals("Val1 is null, val2 is null, val3 is null", result);
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
- new Integer[] { null, i2, i3 });
+ new Integer[] { null, i2, i3 }).getMessage();
assertEquals("Val1 is null, val2 is 2, val3 is 3", result);
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
- new Integer[] { null, null, i3 });
+ new Integer[] { null, null, i3 }).getMessage();
assertEquals("Val1 is null, val2 is null, val3 is 3", result);
}
public void testOneParameter() {
- result = MessageFormatter.format("Value is {}.", i3);
+ result = MessageFormatter.format("Value is {}.", i3).getMessage();
assertEquals("Value is 3.", result);
- result = MessageFormatter.format("Value is {", i3);
+ result = MessageFormatter.format("Value is {", i3).getMessage();
assertEquals("Value is {", result);
- result = MessageFormatter.format("{} is larger than 2.", i3);
+ result = MessageFormatter.format("{} is larger than 2.", i3).getMessage();
assertEquals("3 is larger than 2.", result);
- result = MessageFormatter.format("No subst", i3);
+ result = MessageFormatter.format("No subst", i3).getMessage();
assertEquals("No subst", result);
- result = MessageFormatter.format("Incorrect {subst", i3);
+ result = MessageFormatter.format("Incorrect {subst", i3).getMessage();
assertEquals("Incorrect {subst", result);
- result = MessageFormatter.format("Value is {bla} {}", i3);
+ result = MessageFormatter.format("Value is {bla} {}", i3).getMessage();
assertEquals("Value is {bla} 3", result);
- result = MessageFormatter.format("Escaped \\{} subst", i3);
+ result = MessageFormatter.format("Escaped \\{} subst", i3).getMessage();
assertEquals("Escaped {} subst", result);
- result = MessageFormatter.format("{Escaped", i3);
+ result = MessageFormatter.format("{Escaped", i3).getMessage();
assertEquals("{Escaped", result);
- result = MessageFormatter.format("\\{}Escaped", i3);
+ result = MessageFormatter.format("\\{}Escaped", i3).getMessage();
assertEquals("{}Escaped", result);
- result = MessageFormatter.format("File name is {{}}.", "App folder.zip");
+ result = MessageFormatter.format("File name is {{}}.", "App folder.zip")
+ .getMessage();
assertEquals("File name is {App folder.zip}.", result);
// escaping the escape character
result = MessageFormatter
- .format("File name is C:\\\\{}.", "App folder.zip");
+ .format("File name is C:\\\\{}.", "App folder.zip").getMessage();
assertEquals("File name is C:\\App folder.zip.", result);
}
public void testTwoParameters() {
- result = MessageFormatter.format("Value {} is smaller than {}.", i1, i2);
+ result = MessageFormatter.format("Value {} is smaller than {}.", i1, i2)
+ .getMessage();
assertEquals("Value 1 is smaller than 2.", result);
- result = MessageFormatter.format("Value {} is smaller than {}", i1, i2);
+ result = MessageFormatter.format("Value {} is smaller than {}", i1, i2)
+ .getMessage();
assertEquals("Value 1 is smaller than 2", result);
- result = MessageFormatter.format("{}{}", i1, i2);
+ result = MessageFormatter.format("{}{}", i1, i2).getMessage();
assertEquals("12", result);
- result = MessageFormatter.format("Val1={}, Val2={", i1, i2);
+ result = MessageFormatter.format("Val1={}, Val2={", i1, i2).getMessage();
assertEquals("Val1=1, Val2={", result);
- result = MessageFormatter.format("Value {} is smaller than \\{}", i1, i2);
+ result = MessageFormatter.format("Value {} is smaller than \\{}", i1, i2)
+ .getMessage();
assertEquals("Value 1 is smaller than {}", result);
result = MessageFormatter.format("Value {} is smaller than \\{} tail", i1,
- i2);
+ i2).getMessage();
assertEquals("Value 1 is smaller than {} tail", result);
- result = MessageFormatter.format("Value {} is smaller than \\{", i1, i2);
+ result = MessageFormatter.format("Value {} is smaller than \\{", i1, i2)
+ .getMessage();
assertEquals("Value 1 is smaller than \\{", result);
- result = MessageFormatter
- .format("Value {} is smaller than {tail", i1, i2);
+ result = MessageFormatter.format("Value {} is smaller than {tail", i1, i2)
+ .getMessage();
assertEquals("Value 1 is smaller than {tail", result);
- result = MessageFormatter.format("Value \\{} is smaller than {}", i1, i2);
+ result = MessageFormatter.format("Value \\{} is smaller than {}", i1, i2)
+ .getMessage();
assertEquals("Value {} is smaller than 1", result);
}
-
public void testExceptionInToString() {
Object o = new Object() {
public String toString() {
throw new IllegalStateException("a");
}
};
- result = MessageFormatter.format("Troublesome object {}", o);
+ result = MessageFormatter.format("Troublesome object {}", o).getMessage();
assertEquals("Troublesome object [FAILED toString()]", result);
-
+
}
-
+
public void testNullArray() {
String msg0 = "msg0";
String msg1 = "msg1 {}";
@@ -170,41 +177,45 @@ public class MessageFormatterTest extends TestCase {
Object[] args = null;
- result = MessageFormatter.arrayFormat(msg0, args);
+ result = MessageFormatter.arrayFormat(msg0, args).getMessage();
assertEquals(msg0, result);
- result = MessageFormatter.arrayFormat(msg1, args);
+ result = MessageFormatter.arrayFormat(msg1, args).getMessage();
assertEquals(msg1, result);
- result = MessageFormatter.arrayFormat(msg2, args);
+ result = MessageFormatter.arrayFormat(msg2, args).getMessage();
assertEquals(msg2, result);
- result = MessageFormatter.arrayFormat(msg3, args);
+ result = MessageFormatter.arrayFormat(msg3, args).getMessage();
assertEquals(msg3, result);
}
// tests the case when the parameters are supplied in a single array
public void testArrayFormat() {
result = MessageFormatter.arrayFormat(
- "Value {} is smaller than {} and {}.", ia0);
+ "Value {} is smaller than {} and {}.", ia0).getMessage();
assertEquals("Value 1 is smaller than 2 and 3.", result);
- result = MessageFormatter.arrayFormat("{}{}{}", ia0);
+ result = MessageFormatter.arrayFormat("{}{}{}", ia0).getMessage();
assertEquals("123", result);
- result = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia0);
+ result = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia0)
+ .getMessage();
assertEquals("Value 1 is smaller than 2.", result);
- result = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia0);
+ result = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia0)
+ .getMessage();
assertEquals("Value 1 is smaller than 2", result);
- result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0);
+ result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0)
+ .getMessage();
assertEquals("Val=1, {, Val=2", result);
- result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0);
+ result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0)
+ .getMessage();
assertEquals("Val=1, {, Val=2", result);
- result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia0);
+ result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia0).getMessage();
assertEquals("Val1=1, Val2={", result);
}
@@ -212,58 +223,60 @@ public class MessageFormatterTest extends TestCase {
Integer p0 = i1;
Integer[] p1 = new Integer[] { i2, i3 };
- result = MessageFormatter.format("{}{}", p0, p1);
+ result = MessageFormatter.format("{}{}", p0, p1).getMessage();
assertEquals("1[2, 3]", result);
// Integer[]
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", p1 });
+ result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", p1 })
+ .getMessage();
assertEquals("a[2, 3]", result);
// byte[]
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- new byte[] { 1, 2 } });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", new byte[] { 1, 2 } }).getMessage();
assertEquals("a[1, 2]", result);
// int[]
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- new int[] { 1, 2 } });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", new int[] { 1, 2 } }).getMessage();
assertEquals("a[1, 2]", result);
// float[]
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- new float[] { 1, 2 } });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", new float[] { 1, 2 } }).getMessage();
assertEquals("a[1.0, 2.0]", result);
// double[]
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- new double[] { 1, 2 } });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", new double[] { 1, 2 } }).getMessage();
assertEquals("a[1.0, 2.0]", result);
}
public void testMultiDimensionalArrayValues() {
Integer[][] multiIntegerA = new Integer[][] { ia0, ia1 };
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- multiIntegerA });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", multiIntegerA }).getMessage();
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
int[][] multiIntA = new int[][] { { 1, 2 }, { 10, 20 } };
result = MessageFormatter.arrayFormat("{}{}",
- new Object[] { "a", multiIntA });
+ new Object[] { "a", multiIntA }).getMessage();
assertEquals("a[[1, 2], [10, 20]]", result);
float[][] multiFloatA = new float[][] { { 1, 2 }, { 10, 20 } };
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a",
- multiFloatA });
+ result = MessageFormatter.arrayFormat("{}{}",
+ new Object[] { "a", multiFloatA }).getMessage();
assertEquals("a[[1.0, 2.0], [10.0, 20.0]]", result);
Object[][] multiOA = new Object[][] { ia0, ia1 };
result = MessageFormatter
- .arrayFormat("{}{}", new Object[] { "a", multiOA });
+ .arrayFormat("{}{}", new Object[] { "a", multiOA }).getMessage();
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
Object[][][] _3DOA = new Object[][][] { multiOA, multiOA };
- result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", _3DOA });
+ result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", _3DOA })
+ .getMessage();
assertEquals("a[[[1, 2, 3], [10, 20, 30]], [[1, 2, 3], [10, 20, 30]]]",
result);
}
@@ -272,15 +285,16 @@ public class MessageFormatterTest extends TestCase {
{
Object[] cyclicA = new Object[1];
cyclicA[0] = cyclicA;
- assertEquals("[[...]]", MessageFormatter.arrayFormat("{}", cyclicA));
+ assertEquals("[[...]]", MessageFormatter.arrayFormat("{}", cyclicA).getMessage());
}
{
Object[] a = new Object[2];
a[0] = i1;
- Object[] c = new Object[] {i3, a};
- Object[] b = new Object[] {i2, c};
+ Object[] c = new Object[] { i3, a };
+ Object[] b = new Object[] { i2, c };
a[1] = b;
- assertEquals("1[2, [3, [1, [...]]]]", MessageFormatter.arrayFormat("{}{}", a));
+ assertEquals("1[2, [3, [1, [...]]]]", MessageFormatter.arrayFormat(
+ "{}{}", a).getMessage());
}
}
}
diff --git a/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java b/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
index 75f8e65..b9fcd9f 100644
--- a/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
+++ b/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
@@ -74,7 +74,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage,
new Object[] { arg }, null);
@@ -91,7 +92,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -108,7 +110,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage, argArray, null);
} else {
@@ -152,7 +155,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isTraceEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage,
new Object[] { arg }, null);
@@ -168,7 +172,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isTraceEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -184,7 +189,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isTraceEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.TRACE_INT, formattedMessage, argArray, null);
} else {
@@ -243,7 +249,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage,
new Object[] { arg }, null);
@@ -260,7 +267,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -277,7 +285,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage, argArray, null);
} else {
@@ -321,7 +330,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isDebugEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage,
new Object[] { arg }, null);
@@ -337,7 +347,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isDebugEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -353,7 +364,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isDebugEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.DEBUG_INT, formattedMessage, argArray, null);
} else {
@@ -412,7 +424,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, new Object[] { arg },
null);
@@ -429,7 +442,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -446,7 +460,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, argArray, null);
} else {
@@ -490,7 +505,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isInfoEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, new Object[] { arg },
null);
@@ -506,7 +522,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isInfoEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -522,7 +539,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isInfoEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.INFO_INT, formattedMessage, argArray, null);
} else {
@@ -578,7 +596,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, new Object[] { arg },
null);
@@ -595,7 +614,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -612,7 +632,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, argArray, null);
} else {
@@ -656,7 +677,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isWarnEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, new Object[] { arg },
null);
@@ -672,7 +694,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isWarnEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -688,7 +711,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isWarnEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.WARN_INT, formattedMessage, argArray, null);
} else {
@@ -747,7 +771,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage,
new Object[] { arg }, null);
@@ -764,7 +789,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -781,7 +807,8 @@ public class LoggerWrapper implements Logger {
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(null, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage, argArray, null);
} else {
@@ -825,7 +852,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isErrorEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg);
+ String formattedMessage = MessageFormatter.format(format, arg)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage,
new Object[] { arg }, null);
@@ -841,7 +869,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isErrorEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+ String formattedMessage = MessageFormatter.format(format, arg1, arg2)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage, new Object[] { arg1,
arg2 }, null);
@@ -857,7 +886,8 @@ public class LoggerWrapper implements Logger {
if (!logger.isErrorEnabled())
return;
if (instanceofLAL) {
- String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+ String formattedMessage = MessageFormatter.arrayFormat(format, argArray)
+ .getMessage();
((LocationAwareLogger) logger).log(marker, fqcn,
LocationAwareLogger.ERROR_INT, formattedMessage, argArray, null);
} else {
diff --git a/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java b/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
index 93510b0..635ef25 100644
--- a/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
+++ b/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
@@ -3,6 +3,7 @@ package org.slf4j.ext;
import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
+import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;
@@ -98,10 +99,9 @@ public class XLogger extends LoggerWrapper implements Logger {
} else {
messagePattern = buildMessagePattern(argArray.length);
}
- String formattedMessage = MessageFormatter.arrayFormat(messagePattern,
- argArray);
+ FormattingTuple tp = MessageFormatter.arrayFormat(messagePattern, argArray);
((LocationAwareLogger) logger).log(ENTRY_MARKER, FQCN,
- LocationAwareLogger.TRACE_INT, formattedMessage, argArray, null);
+ LocationAwareLogger.TRACE_INT, tp.getMessage(), argArray, tp.getThrowable());
}
}
@@ -123,10 +123,10 @@ public class XLogger extends LoggerWrapper implements Logger {
*/
public void exit(Object result) {
if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
- String formattedMessage = MessageFormatter.format(EXIT_MESSAGE_1, result);
+ FormattingTuple tp = MessageFormatter.format(EXIT_MESSAGE_1, result);
((LocationAwareLogger) logger).log(EXIT_MARKER, FQCN,
- LocationAwareLogger.TRACE_INT, formattedMessage,
- new Object[] { result }, null);
+ LocationAwareLogger.TRACE_INT, tp.getMessage(),
+ new Object[] { result }, tp.getThrowable());
}
}
diff --git a/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java b/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java
index db3761f..4f2fb4e 100644
--- a/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java
+++ b/slf4j-ext/src/main/java/org/slf4j/instrumentation/LogTransformer.java
@@ -30,272 +30,271 @@ import org.slf4j.helpers.MessageFormatter;
*/
public class LogTransformer implements ClassFileTransformer {
- /**
- * Builder provides a flexible way of configuring some of many options on
- * the parent class instead of providing many constructors.
- *
- * {@link http
- * ://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html}
- *
- */
- public static class Builder {
-
- /**
- * Build and return the LogTransformer corresponding to the options set
- * in this Builder.
- *
- * @return
- */
- public LogTransformer build() {
- if (verbose) {
- System.err.println("Creating LogTransformer");
- }
- return new LogTransformer(this);
- }
-
- boolean addEntryExit;
-
- /**
- * Should each method log entry (with parameters) and exit (with
- * parameters and returnvalue)?
- *
- * @param b
- * value of flag
- * @return
- */
- public Builder addEntryExit(boolean b) {
- addEntryExit = b;
- return this;
- }
-
- boolean addVariableAssignment;
-
- // private Builder addVariableAssignment(boolean b) {
- // System.err.println("cannot currently log variable assignments.");
- // addVariableAssignment = b;
- // return this;
- // }
-
- boolean verbose;
-
- /**
- * Should LogTransformer be verbose in what it does? This currently list
- * the names of the classes being processed.
- *
- * @param b
- * @return
- */
- public Builder verbose(boolean b) {
- verbose = b;
- return this;
- }
-
- String[] ignore = { "org/slf4j/", "ch/qos/logback/",
- "org/apache/log4j/" };
-
- public Builder ignore(String[] strings) {
- this.ignore = strings;
- return this;
- }
-
- private String level = "info";
-
- public Builder level(String level) {
- level = level.toLowerCase();
- if (level.equals("info") || level.equals("debug")
- || level.equals("trace")) {
- this.level = level;
- } else {
- if (verbose) {
- System.err.println("level not info/debug/trace : " + level);
- }
- }
- return this;
- }
- }
-
- private String level;
- private String levelEnabled;
-
- private LogTransformer(Builder builder) {
- String s = "WARNING: javassist not available on classpath for javaagent, log statements will not be added";
- try {
- if (Class.forName("javassist.ClassPool") == null) {
- System.err.println(s);
- }
- } catch (ClassNotFoundException e) {
- System.err.println(s);
- }
-
- this.addEntryExit = builder.addEntryExit;
- // this.addVariableAssignment = builder.addVariableAssignment;
- this.verbose = builder.verbose;
- this.ignore = builder.ignore;
- this.level = builder.level;
- this.levelEnabled = "is" + builder.level.substring(0, 1).toUpperCase()
- + builder.level.substring(1) + "Enabled";
- }
-
- private boolean addEntryExit;
- // private boolean addVariableAssignment;
- private boolean verbose;
- private String[] ignore;
-
- public byte[] transform(ClassLoader loader, String className,
- Class<?> clazz, ProtectionDomain domain, byte[] bytes) {
-
- try {
- return transform0(className, clazz, domain, bytes);
- } catch (Exception e) {
- System.err.println("Could not instrument " + className);
- e.printStackTrace();
- return bytes;
- }
- }
-
- /**
- * transform0 sees if the className starts with any of the namespaces to
- * ignore, if so it is returned unchanged. Otherwise it is processed by
- * doClass(...)
- *
- * @param className
- * @param clazz
- * @param domain
- * @param bytes
- * @return
- */
-
- private byte[] transform0(String className, Class<?> clazz,
- ProtectionDomain domain, byte[] bytes) {
-
- try {
- for (int i = 0; i < ignore.length; i++) {
- if (className.startsWith(ignore[i])) {
- return bytes;
- }
- }
- String slf4jName = "org.slf4j.LoggerFactory";
- try {
- if (domain != null && domain.getClassLoader() != null) {
- domain.getClassLoader().loadClass(slf4jName);
- } else {
- if (verbose) {
- System.err
- .println("Skipping "
- + className
- + " as it doesn't have a domain or a class loader.");
- }
- return bytes;
- }
- } catch (ClassNotFoundException e) {
- if (verbose) {
- System.err.println("Skipping " + className
- + " as slf4j is not available to it");
- }
- return bytes;
- }
- if (verbose) {
- System.err.println("Processing " + className);
- }
- return doClass(className, clazz, bytes);
- } catch (Throwable e) {
- System.out.println("e = " + e);
- return bytes;
- }
- }
-
- private String loggerName;
-
- /**
- * doClass() process a single class by first creates a class description
- * from the byte codes. If it is a class (i.e. not an interface) the methods
- * defined have bodies, and a static final logger object is added with the
- * name of this class as an argument, and each method then gets processed
- * with doMethod(...) to have logger calls added.
- *
- * @param name
- * class name (slashes separate, not dots)
- * @param clazz
- * @param b
- * @return
- */
- private byte[] doClass(String name, Class<?> clazz, byte[] b) {
- ClassPool pool = ClassPool.getDefault();
- CtClass cl = null;
- try {
- cl = pool.makeClass(new ByteArrayInputStream(b));
- if (cl.isInterface() == false) {
-
- loggerName = "_____log";
-
- // We have to declare the log variable.
-
- String pattern1 = "private static org.slf4j.Logger {};";
- String loggerDefinition = format(pattern1, loggerName);
- CtField field = CtField.make(loggerDefinition, cl);
-
- // and assign it the appropriate value.
-
- String pattern2 = "org.slf4j.LoggerFactory.getLogger({}.class);";
- String replace = name.replace('/', '.');
- String getLogger = format(pattern2, replace);
-
- cl.addField(field, getLogger);
-
- // then check every behaviour (which includes methods). We are
- // only
- // interested in non-empty ones, as they have code.
- // NOTE: This will be changed, as empty methods should be
- // instrumented too.
-
- CtBehavior[] methods = cl.getDeclaredBehaviors();
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].isEmpty() == false) {
- doMethod(methods[i]);
- }
- }
- b = cl.toBytecode();
- }
- } catch (Exception e) {
- System.err.println("Could not instrument " + name + ", " + e);
- e.printStackTrace(System.err);
- } finally {
- if (cl != null) {
- cl.detach();
- }
- }
- return b;
- }
-
- /**
- * process a single method - this means add entry/exit logging if requested.
- * It is only called for methods with a body.
- *
- * @param method
- * method to work on
- * @throws NotFoundException
- * @throws CannotCompileException
- */
- private void doMethod(CtBehavior method) throws NotFoundException,
- CannotCompileException {
-
- String signature = JavassistHelper.getSignature(method);
- String returnValue = JavassistHelper.returnValue(method);
-
- if (addEntryExit) {
- String messagePattern = "if ({}.{}()) {}.{}(\">> {}\");";
- Object[] arg1 = new Object[] { loggerName, levelEnabled,
- loggerName, level, signature };
- String before = MessageFormatter.arrayFormat(messagePattern, arg1);
- // System.out.println(before);
- method.insertBefore(before);
-
- String messagePattern2 = "if ({}.{}()) {}.{}(\"<< {}{}\");";
- Object[] arg2 = new Object[] { loggerName, levelEnabled,
- loggerName, level, signature, returnValue };
- String after = MessageFormatter.arrayFormat(messagePattern2, arg2);
- // System.out.println(after);
- method.insertAfter(after);
- }
- }
+ /**
+ * Builder provides a flexible way of configuring some of many options on the
+ * parent class instead of providing many constructors.
+ *
+ * {@link http
+ * ://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html}
+ *
+ */
+ public static class Builder {
+
+ /**
+ * Build and return the LogTransformer corresponding to the options set in
+ * this Builder.
+ *
+ * @return
+ */
+ public LogTransformer build() {
+ if (verbose) {
+ System.err.println("Creating LogTransformer");
+ }
+ return new LogTransformer(this);
+ }
+
+ boolean addEntryExit;
+
+ /**
+ * Should each method log entry (with parameters) and exit (with parameters
+ * and returnvalue)?
+ *
+ * @param b
+ * value of flag
+ * @return
+ */
+ public Builder addEntryExit(boolean b) {
+ addEntryExit = b;
+ return this;
+ }
+
+ boolean addVariableAssignment;
+
+ // private Builder addVariableAssignment(boolean b) {
+ // System.err.println("cannot currently log variable assignments.");
+ // addVariableAssignment = b;
+ // return this;
+ // }
+
+ boolean verbose;
+
+ /**
+ * Should LogTransformer be verbose in what it does? This currently list the
+ * names of the classes being processed.
+ *
+ * @param b
+ * @return
+ */
+ public Builder verbose(boolean b) {
+ verbose = b;
+ return this;
+ }
+
+ String[] ignore = { "org/slf4j/", "ch/qos/logback/", "org/apache/log4j/" };
+
+ public Builder ignore(String[] strings) {
+ this.ignore = strings;
+ return this;
+ }
+
+ private String level = "info";
+
+ public Builder level(String level) {
+ level = level.toLowerCase();
+ if (level.equals("info") || level.equals("debug")
+ || level.equals("trace")) {
+ this.level = level;
+ } else {
+ if (verbose) {
+ System.err.println("level not info/debug/trace : " + level);
+ }
+ }
+ return this;
+ }
+ }
+
+ private String level;
+ private String levelEnabled;
+
+ private LogTransformer(Builder builder) {
+ String s = "WARNING: javassist not available on classpath for javaagent, log statements will not be added";
+ try {
+ if (Class.forName("javassist.ClassPool") == null) {
+ System.err.println(s);
+ }
+ } catch (ClassNotFoundException e) {
+ System.err.println(s);
+ }
+
+ this.addEntryExit = builder.addEntryExit;
+ // this.addVariableAssignment = builder.addVariableAssignment;
+ this.verbose = builder.verbose;
+ this.ignore = builder.ignore;
+ this.level = builder.level;
+ this.levelEnabled = "is" + builder.level.substring(0, 1).toUpperCase()
+ + builder.level.substring(1) + "Enabled";
+ }
+
+ private boolean addEntryExit;
+ // private boolean addVariableAssignment;
+ private boolean verbose;
+ private String[] ignore;
+
+ public byte[] transform(ClassLoader loader, String className, Class<?> clazz,
+ ProtectionDomain domain, byte[] bytes) {
+
+ try {
+ return transform0(className, clazz, domain, bytes);
+ } catch (Exception e) {
+ System.err.println("Could not instrument " + className);
+ e.printStackTrace();
+ return bytes;
+ }
+ }
+
+ /**
+ * transform0 sees if the className starts with any of the namespaces to
+ * ignore, if so it is returned unchanged. Otherwise it is processed by
+ * doClass(...)
+ *
+ * @param className
+ * @param clazz
+ * @param domain
+ * @param bytes
+ * @return
+ */
+
+ private byte[] transform0(String className, Class<?> clazz,
+ ProtectionDomain domain, byte[] bytes) {
+
+ try {
+ for (int i = 0; i < ignore.length; i++) {
+ if (className.startsWith(ignore[i])) {
+ return bytes;
+ }
+ }
+ String slf4jName = "org.slf4j.LoggerFactory";
+ try {
+ if (domain != null && domain.getClassLoader() != null) {
+ domain.getClassLoader().loadClass(slf4jName);
+ } else {
+ if (verbose) {
+ System.err.println("Skipping " + className
+ + " as it doesn't have a domain or a class loader.");
+ }
+ return bytes;
+ }
+ } catch (ClassNotFoundException e) {
+ if (verbose) {
+ System.err.println("Skipping " + className
+ + " as slf4j is not available to it");
+ }
+ return bytes;
+ }
+ if (verbose) {
+ System.err.println("Processing " + className);
+ }
+ return doClass(className, clazz, bytes);
+ } catch (Throwable e) {
+ System.out.println("e = " + e);
+ return bytes;
+ }
+ }
+
+ private String loggerName;
+
+ /**
+ * doClass() process a single class by first creates a class description from
+ * the byte codes. If it is a class (i.e. not an interface) the methods
+ * defined have bodies, and a static final logger object is added with the
+ * name of this class as an argument, and each method then gets processed with
+ * doMethod(...) to have logger calls added.
+ *
+ * @param name
+ * class name (slashes separate, not dots)
+ * @param clazz
+ * @param b
+ * @return
+ */
+ private byte[] doClass(String name, Class<?> clazz, byte[] b) {
+ ClassPool pool = ClassPool.getDefault();
+ CtClass cl = null;
+ try {
+ cl = pool.makeClass(new ByteArrayInputStream(b));
+ if (cl.isInterface() == false) {
+
+ loggerName = "_____log";
+
+ // We have to declare the log variable.
+
+ String pattern1 = "private static org.slf4j.Logger {};";
+ String loggerDefinition = format(pattern1, loggerName).getMessage();
+ CtField field = CtField.make(loggerDefinition, cl);
+
+ // and assign it the appropriate value.
+
+ String pattern2 = "org.slf4j.LoggerFactory.getLogger({}.class);";
+ String replace = name.replace('/', '.');
+ String getLogger = format(pattern2, replace).getMessage();
+
+ cl.addField(field, getLogger);
+
+ // then check every behaviour (which includes methods). We are
+ // only
+ // interested in non-empty ones, as they have code.
+ // NOTE: This will be changed, as empty methods should be
+ // instrumented too.
+
+ CtBehavior[] methods = cl.getDeclaredBehaviors();
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].isEmpty() == false) {
+ doMethod(methods[i]);
+ }
+ }
+ b = cl.toBytecode();
+ }
+ } catch (Exception e) {
+ System.err.println("Could not instrument " + name + ", " + e);
+ e.printStackTrace(System.err);
+ } finally {
+ if (cl != null) {
+ cl.detach();
+ }
+ }
+ return b;
+ }
+
+ /**
+ * process a single method - this means add entry/exit logging if requested.
+ * It is only called for methods with a body.
+ *
+ * @param method
+ * method to work on
+ * @throws NotFoundException
+ * @throws CannotCompileException
+ */
+ private void doMethod(CtBehavior method) throws NotFoundException,
+ CannotCompileException {
+
+ String signature = JavassistHelper.getSignature(method);
+ String returnValue = JavassistHelper.returnValue(method);
+
+ if (addEntryExit) {
+ String messagePattern = "if ({}.{}()) {}.{}(\">> {}\");";
+ Object[] arg1 = new Object[] { loggerName, levelEnabled, loggerName,
+ level, signature };
+ String before = MessageFormatter.arrayFormat(messagePattern, arg1)
+ .getMessage();
+ // System.out.println(before);
+ method.insertBefore(before);
+
+ String messagePattern2 = "if ({}.{}()) {}.{}(\"<< {}{}\");";
+ Object[] arg2 = new Object[] { loggerName, levelEnabled, loggerName,
+ level, signature, returnValue };
+ String after = MessageFormatter.arrayFormat(messagePattern2, arg2)
+ .getMessage();
+ // System.out.println(after);
+ method.insertAfter(after);
+ }
+ }
}
\ No newline at end of file
diff --git a/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerAdapter.java b/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerAdapter.java
index 9cb2a5e..31c57e0 100644
--- a/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerAdapter.java
+++ b/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerAdapter.java
@@ -27,6 +27,7 @@ package org.slf4j.impl;
import org.apache.commons.logging.Log;
import org.slf4j.Logger;
+import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
@@ -85,8 +86,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void trace(String format, Object arg) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- log.trace(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log.trace(ft.getMessage(), ft.getThrowable());
}
}
@@ -108,8 +109,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void trace(String format, Object arg1, Object arg2) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log.trace(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log.trace(ft.getMessage(), ft.getThrowable());
}
}
@@ -128,8 +129,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void trace(String format, Object[] argArray) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log.trace(msgStr);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log.trace(ft.getMessage(), ft.getThrowable());
}
}
@@ -183,8 +184,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void debug(String format, Object arg) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- log.debug(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log.debug(ft.getMessage(), ft.getThrowable());
}
}
@@ -206,8 +207,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void debug(String format, Object arg1, Object arg2) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log.debug(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log.debug(ft.getMessage(), ft.getThrowable());
}
}
@@ -226,8 +227,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void debug(String format, Object[] argArray) {
if (log.isDebugEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log.debug(msgStr);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log.debug(ft.getMessage(), ft.getThrowable());
}
}
@@ -279,8 +280,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
public void info(String format, Object arg) {
if (log.isInfoEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- log.info(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log.info(ft.getMessage(), ft.getThrowable());
}
}
/**
@@ -301,8 +302,9 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void info(String format, Object arg1, Object arg2) {
if (log.isInfoEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log.info(msgStr);
+
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log.info(ft.getMessage(), ft.getThrowable());
}
}
@@ -320,8 +322,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void info(String format, Object[] argArray) {
if (log.isInfoEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log.info(msgStr);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log.info(ft.getMessage(), ft.getThrowable());
}
}
@@ -373,8 +375,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void warn(String format, Object arg) {
if (log.isWarnEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- log.warn(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log.warn(ft.getMessage(), ft.getThrowable());
}
}
@@ -396,8 +398,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void warn(String format, Object arg1, Object arg2) {
if (log.isWarnEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log.warn(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log.warn(ft.getMessage(), ft.getThrowable());
}
}
@@ -415,8 +417,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void warn(String format, Object[] argArray) {
if (log.isWarnEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log.warn(msgStr);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log.warn(ft.getMessage(), ft.getThrowable());
}
}
@@ -470,8 +472,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void error(String format, Object arg) {
if (log.isErrorEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- log.error(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log.error(ft.getMessage(), ft.getThrowable());
}
}
@@ -493,8 +495,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void error(String format, Object arg1, Object arg2) {
if (log.isErrorEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log.error(msgStr);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log.error(ft.getMessage(), ft.getThrowable());
}
}
@@ -512,8 +514,8 @@ public final class JCLLoggerAdapter extends MarkerIgnoringBase {
*/
public void error(String format, Object[] argArray) {
if (log.isErrorEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log.error(msgStr);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log.error(ft.getMessage(), ft.getThrowable());
}
}
diff --git a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java
index 55a8d5e..1c9b0cc 100644
--- a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java
+++ b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerAdapter.java
@@ -38,6 +38,7 @@ import java.util.logging.LogRecord;
import org.slf4j.Logger;
import org.slf4j.Marker;
+import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;
@@ -102,8 +103,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object arg) {
if (logger.isLoggable(Level.FINEST)) {
- String msgStr = MessageFormatter.format(format, arg);
- log(SELF, Level.FINEST, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
}
}
@@ -125,8 +126,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.FINEST)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log(SELF, Level.FINEST, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
}
}
@@ -146,8 +147,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object[] argArray) {
if (logger.isLoggable(Level.FINEST)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log(SELF, Level.FINEST, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
}
}
@@ -201,8 +202,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object arg) {
if (logger.isLoggable(Level.FINE)) {
- String msgStr = MessageFormatter.format(format, arg);
- log(SELF, Level.FINE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
}
}
@@ -224,8 +225,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.FINE)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log(SELF, Level.FINE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
}
}
@@ -245,8 +246,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object[] argArray) {
if (logger.isLoggable(Level.FINE)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log(SELF, Level.FINE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
}
}
@@ -300,8 +301,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object arg) {
if (logger.isLoggable(Level.INFO)) {
- String msgStr = MessageFormatter.format(format, arg);
- log(SELF, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -323,8 +324,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.INFO)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log(SELF, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -344,8 +345,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object[] argArray) {
if (logger.isLoggable(Level.INFO)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log(SELF, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -402,8 +403,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object arg) {
if (logger.isLoggable(Level.WARNING)) {
- String msgStr = MessageFormatter.format(format, arg);
- log(SELF, Level.WARNING, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
}
}
@@ -425,8 +426,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.WARNING)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log(SELF, Level.WARNING, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
}
}
@@ -446,8 +447,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object[] argArray) {
if (logger.isLoggable(Level.WARNING)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log(SELF, Level.WARNING, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable());
}
}
@@ -503,8 +504,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object arg) {
if (logger.isLoggable(Level.SEVERE)) {
- String msgStr = MessageFormatter.format(format, arg);
- log(SELF, Level.SEVERE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
}
}
@@ -526,8 +527,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.SEVERE)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- log(SELF, Level.SEVERE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
}
}
@@ -547,8 +548,8 @@ public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object[] argArray) {
if (logger.isLoggable(Level.SEVERE)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- log(SELF, Level.SEVERE, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
}
}
diff --git a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java
index bfe6444..51cecb4 100644
--- a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java
+++ b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerAdapter.java
@@ -29,6 +29,7 @@ import java.io.Serializable;
import org.apache.log4j.Level;
import org.slf4j.Logger;
import org.slf4j.Marker;
+import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;
@@ -125,8 +126,9 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object arg) {
if (isTraceEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft
+ .getMessage(), ft.getThrowable());
}
}
@@ -148,8 +150,9 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object arg1, Object arg2) {
if (isTraceEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft
+ .getMessage(), ft.getThrowable());
}
}
@@ -169,8 +172,9 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void trace(String format, Object[] argArray) {
if (isTraceEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft
+ .getMessage(), ft.getThrowable());
}
}
@@ -221,8 +225,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object arg) {
if (logger.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- logger.log(FQCN, Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}
@@ -244,8 +248,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object arg1, Object arg2) {
if (logger.isDebugEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- logger.log(FQCN, Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}
@@ -265,8 +269,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void debug(String format, Object[] argArray) {
if (logger.isDebugEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- logger.log(FQCN, Level.DEBUG, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}
@@ -316,8 +320,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object arg) {
if (logger.isInfoEnabled()) {
- String msgStr = MessageFormatter.format(format, arg);
- logger.log(FQCN, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -339,8 +343,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object arg1, Object arg2) {
if (logger.isInfoEnabled()) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- logger.log(FQCN, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -360,8 +364,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void info(String format, Object[] argArray) {
if (logger.isInfoEnabled()) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- logger.log(FQCN, Level.INFO, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
@@ -413,8 +417,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object arg) {
if (logger.isEnabledFor(Level.WARN)) {
- String msgStr = MessageFormatter.format(format, arg);
- logger.log(FQCN, Level.WARN, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
@@ -436,8 +440,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object arg1, Object arg2) {
if (logger.isEnabledFor(Level.WARN)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- logger.log(FQCN, Level.WARN, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
@@ -457,8 +461,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void warn(String format, Object[] argArray) {
if (logger.isEnabledFor(Level.WARN)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- logger.log(FQCN, Level.WARN, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
@@ -510,8 +514,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object arg) {
if (logger.isEnabledFor(Level.ERROR)) {
- String msgStr = MessageFormatter.format(format, arg);
- logger.log(FQCN, Level.ERROR, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg);
+ logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable());
}
}
@@ -533,8 +537,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object arg1, Object arg2) {
if (logger.isEnabledFor(Level.ERROR)) {
- String msgStr = MessageFormatter.format(format, arg1, arg2);
- logger.log(FQCN, Level.ERROR, msgStr, null);
+ FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
+ logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable());
}
}
@@ -554,8 +558,8 @@ public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements
*/
public void error(String format, Object[] argArray) {
if (logger.isEnabledFor(Level.ERROR)) {
- String msgStr = MessageFormatter.arrayFormat(format, argArray);
- logger.log(FQCN, Level.ERROR, msgStr, null);
+ FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
+ logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable());
}
}
diff --git a/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLogger.java b/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLogger.java
index 810d02c..cf33b35 100644
--- a/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLogger.java
+++ b/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLogger.java
@@ -33,18 +33,19 @@
package org.slf4j.impl;
+import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
/**
- * A simple (and direct) implementation that logs messages of level
- * INFO or higher on the console (<code>System.err<code>).
- *
+ * A simple (and direct) implementation that logs messages of level INFO or
+ * higher on the console (<code>System.err<code>).
+ *
* <p>The output includes the relative time in milliseconds, thread
* name, the level, logger name, and the message followed by the line
* separator for the host. In log4j terms it amounts to the "%r [%t]
* %level %logger - %m%n" pattern. </p>
- *
+ *
* <p>Sample output follows.</p>
<pre>
176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
@@ -58,19 +59,19 @@ import org.slf4j.helpers.MessageFormatter;
at org.log4j.examples.Sort.main(Sort.java:64)
467 [main] INFO examples.Sort - Exiting main method.
</pre>
- *
+ *
* @author Ceki Gülcü
*/
public class SimpleLogger extends MarkerIgnoringBase {
-
+
private static final long serialVersionUID = -6560244151660620173L;
-
+
/**
* Mark the time when this class gets loaded into memory.
*/
private static long startTime = System.currentTimeMillis();
- public static final String LINE_SEPARATOR =
- System.getProperty("line.separator");
+ public static final String LINE_SEPARATOR = System
+ .getProperty("line.separator");
private static String INFO_STR = "INFO";
private static String WARN_STR = "WARN";
private static String ERROR_STR = "ERROR";
@@ -85,6 +86,7 @@ public class SimpleLogger extends MarkerIgnoringBase {
/**
* Always returns false.
+ *
* @return always false
*/
public boolean isTraceEnabled() {
@@ -92,25 +94,24 @@ public class SimpleLogger extends MarkerIgnoringBase {
}
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the TRACE level.
+ * A NOP implementation, as this logger is permanently disabled for the TRACE
+ * level.
*/
public void trace(String msg) {
// NOP
}
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the TRACE level.
+ * A NOP implementation, as this logger is permanently disabled for the TRACE
+ * level.
*/
public void trace(String format, Object param1) {
// NOP
}
-
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the TRACE level.
+ * A NOP implementation, as this logger is permanently disabled for the TRACE
+ * level.
*/
public void trace(String format, Object param1, Object param2) {
// NOP
@@ -119,18 +120,18 @@ public class SimpleLogger extends MarkerIgnoringBase {
public void trace(String format, Object[] argArray) {
// NOP
}
-
+
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the TRACE level.
+ * A NOP implementation, as this logger is permanently disabled for the TRACE
+ * level.
*/
public void trace(String msg, Throwable t) {
// NOP
}
-
/**
* Always returns false.
+ *
* @return always false
*/
public boolean isDebugEnabled() {
@@ -138,25 +139,24 @@ public class SimpleLogger extends MarkerIgnoringBase {
}
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the DEBUG level.
+ * A NOP implementation, as this logger is permanently disabled for the DEBUG
+ * level.
*/
public void debug(String msg) {
// NOP
}
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the DEBUG level.
+ * A NOP implementation, as this logger is permanently disabled for the DEBUG
+ * level.
*/
public void debug(String format, Object param1) {
// NOP
}
-
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the DEBUG level.
+ * A NOP implementation, as this logger is permanently disabled for the DEBUG
+ * level.
*/
public void debug(String format, Object param1, Object param2) {
// NOP
@@ -165,10 +165,10 @@ public class SimpleLogger extends MarkerIgnoringBase {
public void debug(String format, Object[] argArray) {
// NOP
}
-
+
/**
- * A NOP implementation, as this logger is permanently disabled for
- * the DEBUG level.
+ * A NOP implementation, as this logger is permanently disabled for the DEBUG
+ * level.
*/
public void debug(String msg, Throwable t) {
// NOP
@@ -177,7 +177,7 @@ public class SimpleLogger extends MarkerIgnoringBase {
/**
* This is our internal implementation for logging regular (non-parameterized)
* log messages.
- *
+ *
* @param level
* @param message
* @param t
@@ -211,18 +211,18 @@ public class SimpleLogger extends MarkerIgnoringBase {
/**
* For formatted messages, first substitute arguments and then log.
- *
+ *
* @param level
* @param format
* @param param1
* @param param2
*/
- private void formatAndLog(
- String level, String format, Object arg1, Object arg2) {
- String message = MessageFormatter.format(format, arg1, arg2);
- log(level, message, null);
+ private void formatAndLog(String level, String format, Object arg1,
+ Object arg2) {
+ FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
+ log(level, tp.getMessage(), tp.getThrowable());
}
-
+
/**
* For formatted messages, first substitute arguments and then log.
*
@@ -231,8 +231,8 @@ public class SimpleLogger extends MarkerIgnoringBase {
* @param argArray
*/
private void formatAndLog(String level, String format, Object[] argArray) {
- String message = MessageFormatter.arrayFormat(format, argArray);
- log(level, message, null);
+ FormattingTuple tp = MessageFormatter.arrayFormat(format, argArray);
+ log(level, tp.getMessage(), tp.getThrowable());
}
/**
@@ -274,7 +274,6 @@ public class SimpleLogger extends MarkerIgnoringBase {
formatAndLog(INFO_STR, format, argArray);
}
-
/**
* Log a message of level INFO, including an exception.
*/
@@ -288,11 +287,11 @@ public class SimpleLogger extends MarkerIgnoringBase {
public boolean isWarnEnabled() {
return true;
}
-
+
/**
* A simple implementation which always logs messages of level WARN according
* to the format outlined above.
- */
+ */
public void warn(String msg) {
log(WARN_STR, msg, null);
}
@@ -367,7 +366,6 @@ public class SimpleLogger extends MarkerIgnoringBase {
formatAndLog(ERROR_STR, format, argArray);
}
-
/**
* Log a message of level ERROR, including an exception.
*/
-----------------------------------------------------------------------
hooks/post-receive
--
SLF4J: Simple Logging Facade for Java
1
0

[Bug 127] LocationAwareLogger does not have a method that accepts the argument array
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
09 Apr '10
http://bugzilla.slf4j.org/show_bug.cgi?id=127
--- Comment #6 from Ceki Gulcu <lists(a)slf4j.org> 2010-04-09 11:39:33 ---
I agree with you that this is a good time to consider the inclusion of Message
related API changes.
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
1
0

[Bug 127] LocationAwareLogger does not have a method that accepts the argument array
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
by bugzilla-daemon@pixie.qos.ch 09 Apr '10
09 Apr '10
http://bugzilla.slf4j.org/show_bug.cgi?id=127
--- Comment #5 from Ralph Goers <rgoers(a)apache.org> 2010-04-09 04:21:44 ---
Gee, if you are going to make the interface incompatible anyway why not add the
methods that take a Message as well?
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
1
0