Discussion:
[jira] [Created] (LOG4J2-796) Log4J2 API not logging correct message with SL4J Simple Logger
Yogesh Rao (JIRA)
2014-08-24 14:27:37 UTC
Permalink
Yogesh Rao created LOG4J2-796:
---------------------------------

Summary: Log4J2 API not logging correct message with SL4J Simple Logger
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao


Hi,

Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.

To reproduce the issue use following class and configuration

HelloWorld.java
--------------

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class HelloWorld {

private static final Logger logger = LogManager.getLogger("HelloWorld");

public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}

}

Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7

The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger




--
This message was sent by Atlassian JIRA
(v6.2#6252)
Yogesh Rao (JIRA)
2014-08-24 14:29:37 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14108417#comment-14108417 ]

Yogesh Rao commented on LOG4J2-796:
-----------------------------------

As per [~***@yahoo.com]
"This looks like a bug. The output is the FQCN (fully qualified name of the
logger).
This is probably introduced by the changes made for LOG4J2-555.

Our unit tests are not picking this up because they use
the ch.qos.logback.classic.Logger, which is a LocationAwareLogger and
follows a different code path.
I suspect that Simple Logger is not LocationAware.

I suspect we should change (in SLF4JLogger.logMessage)
logger.debug(fqcn, getMarker(marker), message.getFormattedMessage(),
message.getParameters(), t);
to
logger.debug(getMarker(marker), message.getFormattedMessage(),
message.getParameters(), t);"
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.2#6252)
Yogesh Rao (JIRA)
2014-08-24 14:31:37 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14108418#comment-14108418 ]

Yogesh Rao commented on LOG4J2-796:
-----------------------------------

need to attach unit test case for this scenario for build purposes.
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.2#6252)
Remko Popma (JIRA)
2014-09-04 15:48:52 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14121480#comment-14121480 ]

Remko Popma commented on LOG4J2-796:
------------------------------------

You raise an interesting point. Currently the log4j-to-slf4j module has these dependencies:
* log4j-api
* slf4j-api
* logback-core [test]
* logback-core-test [test]
* logback-classic [test]

This means that the JUnit tests for the log4j-to-slf4j module have the logback-classic implementation of the Logger interface in the classpath, making it difficult to test against other SLF4J implementations.

I can think of two ways to solve this. One being your suggestion to dynamically set the classpath for each test. Another solution would be to create a different module that contains only JUnit tests for the slf4j-simple implementation. (There may be other solutions I haven't thought of.)

To be honest I find both solutions a bit too heavy; they introduce too much complexity for the relatively small benefit of having a JUnit test for the slf4j-simple implementation.

I'm thinking to just fix this issue and not have a JUnit test.
I'm having trouble committing at the moment, but after I succeed in committing the fix, I'l resolve this issue and you can verify that the solution works.
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Remko Popma (JIRA)
2014-09-04 16:27:51 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma resolved LOG4J2-796.
--------------------------------
Resolution: Fixed
Fix Version/s: 2.1
Assignee: Remko Popma

Fixed in Commit: 33fdc82669899fca266dda91ce607b574101562b.
Please verify and close.
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Assignee: Remko Popma
Fix For: 2.1
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Yogesh Rao (JIRA)
2014-09-04 16:57:51 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Yogesh Rao updated LOG4J2-796:
------------------------------
Attachment: log4j2-796.patch

Hi,

I understand.. Meanwhile i had done the changes already and tested the same. Attaching the patch to the JIRA incase you would like to apply it.
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Assignee: Remko Popma
Fix For: 2.1
Attachments: log4j2-796.patch
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Yogesh Rao (JIRA)
2014-09-05 05:28:26 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122460#comment-14122460 ]

Yogesh Rao commented on LOG4J2-796:
-----------------------------------

Thanks ! The changes are working
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Assignee: Remko Popma
Fix For: 2.1
Attachments: log4j2-796.patch
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Remko Popma (JIRA)
2014-09-05 08:05:27 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-796?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma closed LOG4J2-796.
------------------------------

Thanks for confirming!
Closing this issue.
Post by Yogesh Rao (JIRA)
Log4J2 API not logging correct message with SL4J Simple Logger
--------------------------------------------------------------
Key: LOG4J2-796
URL: https://issues.apache.org/jira/browse/LOG4J2-796
Project: Log4j 2
Issue Type: Bug
Components: API, SLF4J Bridge
Affects Versions: 2.0.1
Reporter: Yogesh Rao
Assignee: Remko Popma
Fix For: 2.1
Attachments: log4j2-796.patch
Hi,
Log4j2 Fails to log the message provided correctly using the log4j-to-slf4j adaptor when the logging implementation used SLF4J-Simple.
To reproduce the issue use following class and configuration
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted", "1/10/1900");
}
}
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Loading...