You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Husby, Joseph P." <Jo...@leidos.com> on 2018/05/29 23:36:44 UTC
Recursive logging issue with curly braces in JSONLayout Object's
toString()
Hello log4j group,
I think we've found a bug... When using JsonLayout for our appender in 2.11.0, an object that has "{}" in its toString will result in a recursive output. Here is a simple code example and resulting output to illustrate the problem:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Test {
public static final Logger log = LogManager.getLogger(Test.class);
public static void main(final String[] args) {
log.info("Testing: {}", new TestObj());
}
static class TestObj {
@Override
public String toString() {
return "This is my toString {} with curly braces";
}
}
}
This produces the following output:
[
{
"thread" : "main",
"level" : "INFO",
"loggerName" : "Test",
"message" : "Testing: This is my toString This is my toString {} with curly braces with curly braces",
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
"instant" : {
"epochSecond" : 1527636365,
"nanoOfSecond" : 40000000
},
"contextMap" : { },
"threadId" : 1,
"threadPriority" : 5
}
]
Note how TestObj's toString is inserted in place of its "{}", resulting in it (sort-of) being logged twice. Is this a known issue?
Thanks!
Joseph Husby
Re: Recursive logging issue with curly braces in JSONLayout Object's toString()
Posted by Joseph Husby <hu...@umn.edu>.
I wrote https://issues.apache.org/jira/browse/LOG4J2-2345 for this issue.
It is very easily reproduced, and I've included a sample program that shows
the problem. However, having never looked at the log4j source, I'm not
confident I'll be able to submit a patch or pull request.
~ Joe ~
On Tue, May 29, 2018 at 6:42 PM Remko Popma <re...@gmail.com> wrote:
> No, this is not a known issue.
> Please raise a ticket on the JIRA issue tracker for this.
>
> The more information about the bug, the faster it is likely to be
> resolved. (Adding a patch or a pull request with unit tests is ideal.)
>
> Remko
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
> > On May 30, 2018, at 8:36, Husby, Joseph P. <Jo...@leidos.com>
> wrote:
> >
> > Hello log4j group,
> >
> > I think we've found a bug... When using JsonLayout for our appender in
> 2.11.0, an object that has "{}" in its toString will result in a recursive
> output. Here is a simple code example and resulting output to illustrate
> the problem:
> >
> > import org.apache.logging.log4j.LogManager;
> > import org.apache.logging.log4j.Logger;
> >
> > public class Test {
> >
> > public static final Logger log = LogManager.getLogger(Test.class);
> >
> > public static void main(final String[] args) {
> > log.info("Testing: {}", new TestObj());
> > }
> >
> > static class TestObj {
> > @Override
> > public String toString() {
> > return "This is my toString {} with curly braces";
> > }
> > }
> > }
> >
> > This produces the following output:
> >
> > [
> > {
> > "thread" : "main",
> > "level" : "INFO",
> > "loggerName" : "Test",
> > "message" : "Testing: This is my toString This is my toString {}
> with curly braces with curly braces",
> > "endOfBatch" : false,
> > "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
> > "instant" : {
> > "epochSecond" : 1527636365,
> > "nanoOfSecond" : 40000000
> > },
> > "contextMap" : { },
> > "threadId" : 1,
> > "threadPriority" : 5
> > }
> > ]
> >
> > Note how TestObj's toString is inserted in place of its "{}", resulting
> in it (sort-of) being logged twice. Is this a known issue?
> >
> > Thanks!
> > Joseph Husby
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Recursive logging issue with curly braces in JSONLayout Object's toString()
Posted by Remko Popma <re...@gmail.com>.
No, this is not a known issue.
Please raise a ticket on the JIRA issue tracker for this.
The more information about the bug, the faster it is likely to be resolved. (Adding a patch or a pull request with unit tests is ideal.)
Remko
(Shameless plug) Every java main() method deserves http://picocli.info
> On May 30, 2018, at 8:36, Husby, Joseph P. <Jo...@leidos.com> wrote:
>
> Hello log4j group,
>
> I think we've found a bug... When using JsonLayout for our appender in 2.11.0, an object that has "{}" in its toString will result in a recursive output. Here is a simple code example and resulting output to illustrate the problem:
>
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
>
> public class Test {
>
> public static final Logger log = LogManager.getLogger(Test.class);
>
> public static void main(final String[] args) {
> log.info("Testing: {}", new TestObj());
> }
>
> static class TestObj {
> @Override
> public String toString() {
> return "This is my toString {} with curly braces";
> }
> }
> }
>
> This produces the following output:
>
> [
> {
> "thread" : "main",
> "level" : "INFO",
> "loggerName" : "Test",
> "message" : "Testing: This is my toString This is my toString {} with curly braces with curly braces",
> "endOfBatch" : false,
> "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
> "instant" : {
> "epochSecond" : 1527636365,
> "nanoOfSecond" : 40000000
> },
> "contextMap" : { },
> "threadId" : 1,
> "threadPriority" : 5
> }
> ]
>
> Note how TestObj's toString is inserted in place of its "{}", resulting in it (sort-of) being logged twice. Is this a known issue?
>
> Thanks!
> Joseph Husby
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org