You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Behrang Saeedzadeh <be...@gmail.com> on 2019/10/25 09:27:21 UTC
What's the purpose of this code, that logs a seemingly meaningless
and possibly misleading exception?
From Tomcat Embedded Core 9.0.26:
@Override
protected void doClose() {
if (log.isDebugEnabled()) {
log.debug("Calling [" + getEndpoint() + "].closeSocket([" +
this + "])", new Exception());
}
Which will log something like:
DEBUG [http-nio-8080-exec-2]
org.apache.tomcat.util.net.NioEndpoint
Calling [org.apache.tomcat.util.net.NioEndpoint@654c1a54
].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@39e9d240
:org.apache.tomcat.util.net.NioChannel@78019ed5:java.nio.channels.SocketChannel[connected
local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
java.lang.Exception: null
at
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at
org.apache.tomcat.util.net.SocketWrapperBase.close(SocketWrapperBase.java:394)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at
org.apache.tomcat.util.net.NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[na:1.8.0_212]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[na:1.8.0_212]
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[tomcat-embed-core-9.0.26.jar:9.0.26]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
To print the stack trace next to the message? Every time I turn on debug
logging this exception catches me by surprise. Why not only print the stack
trace next using
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace for example?
Best regards,
Behrang Saeedzadeh
blog.behrang.org
Re: What's the purpose of this code, that logs a seemingly
meaningless and possibly misleading exception?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Behrang,
On 10/26/19 20:22, Behrang Saeedzadeh wrote:
> Hi Chris,
>
> I suggested “massaging” it a bit before using the output:
>
> stack trace into a StringWriter via a PrintWriter, massage it a
> bit
>
> For example:
>
> StringWriter sw = new StringWriter(); PrintWriter pw = new
> PrintWriter(sw); Exception e = new Exception(); pw.append("Current
> stack trace:\n");for (StackTraceElement stackTraceElement :
> e.getStackTrace()) { pw.append("\tat
> ").append(stackTraceElement.toString()).append("\n"); }
>
> System.out.println(sw.toString());
>
> Which will produce:
>
> Current stack trace: at
> com.example.demo.DemoApplication.baz(DemoApplication.java:33) at
> com.example.demo.DemoApplication.foo(DemoApplication.java:20) at
> com.example.demo.DemoApplication.main(DemoApplication.java:15)
Other than writing to stdout, how is that any different from the
behavior of logger.debug("message", e) ? Are you just trying to get
rid of the "java.lang.Exception: message" part of the output?
I just don't understand how this is an improvement over what is
already there.
- -chris
> On Sun, Oct 27, 2019 at 7:48 AM Christopher Schultz <
> chris@christopherschultz.net> wrote:
>
> Behrang,
>
> On 10/26/19 07:01, Behrang Saeedzadeh wrote:
>>>> I think so. Another option is to create an exception and
>>>> print the stack trace into a StringWriter via a PrintWriter,
>>>> massage it a bit if necessary and add that to the log
>>>> message.
>
> ... which would produce the same output?
>
> What's the goal of the change?
>
> -chris
>
>>>> On Sat, 26 Oct. 2019, 9:12 pm Mark Thomas,
>>>> <ma...@apache.org> wrote:
>>>>
>>>>> On October 25, 2019 9:27:21 AM UTC, Behrang Saeedzadeh <
>>>>> behrangsa@gmail.com> wrote:
>>>>>> From Tomcat Embedded Core 9.0.26:
>>>>>>
>>>>>> @Override protected void doClose() { if
>>>>>> (log.isDebugEnabled()) { log.debug("Calling [" +
>>>>>> getEndpoint() + "].closeSocket([" + this + "])", new
>>>>>> Exception()); }
>>>>>>
>>>>>> Which will log something like:
>>>>>>
>>>>>> DEBUG [http-nio-8080-exec-2]
>>>>>> org.apache.tomcat.util.net.NioEndpoint Calling
>>>>>> [org.apache.tomcat.util.net.NioEndpoint@654c1a54
>>>>>
>>>>>> ].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWr
app
>
>>>>>>
er@39e9d240
>>>>>>
>>>>>>
> :org.apache.tomcat.util.net.NioChannel@78019ed5
>>>>> :java.nio.channels.SocketChannel[connected
>>>>>> local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
>>>>>>
>>>>>> java.lang.Exception: null at org.apache.tomcat.util.net
>>>>> .NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
>>>>>>
>>>>>
[tomcat-embed-core-9.0.26.jar:9.0.26] at
>>>>>> org.apache.tomcat.util.net
>>>>> .SocketWrapperBase.close(SocketWrapperBase.java:394)
>>>>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>>>>> org.apache.tomcat.util.net
>>>>> .NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
>>>>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>>>>> org.apache.tomcat.util.net
>>>>> .NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
>>>>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>>>>> org.apache.tomcat.util.net
>>>>> .SocketProcessorBase.run(SocketProcessorBase.java:49)
>>>>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>>>>
>>>>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecu
tor
>
>>>>>>
.java:1149)
>>>>>>
>>>>>>
> [na:1.8.0_212]
>>>>>> at
>>>>>
>>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExec
uto
>
>>>>>>
r.java:624)
>>>>>>
>>>>>>
> [na:1.8.0_212]
>>>>>> at
>>>>>
>>>>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(Ta
skT
>
>>>>>>
hread.java:61)
>>>>>>
>>>>>>
> [tomcat-embed-core-9.0.26.jar:9.0.26]
>>>>>> at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
>>>>>>
>>>>>> To print the stack trace next to the message?
>>>>>
>>>>> Yes. So the debug message shows what called close().
>>>>>
>>>>>> Every time I turn on debug logging this exception catches
>>>>>> me by surprise. Why not only print the stack trace next
>>>>>> using
>>>>>> org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace
>>>>>>
>>>>>>
for example?
>>>>>
>>>>> Because that adds an entire library as a dependency to
>>>>> support a single debug message. And new Exception() gives
>>>>> what we need without that dependency. Would adding a
>>>>> message to the exception such as "Tracing caller" make
>>>>> things clearer?
>>>>>
>>>>> Mark
>>>>>
>>>>> ------------------------------------------------------------------
- ---
>>>>>
>>>>>
>
>>>>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail:
>>>>> users-help@tomcat.apache.org
>>>>>
>>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>>
>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl225zQACgkQHPApP6U8
pFjiRw/7Blg4irk2PTyydw0WOzl0C7AU6An7DeuVIjzExkCvv0qsici6Q5LwULPF
tEAvPJmwx2DMB/HKWB6cH5RD/GHQlzL6x8CjyQmw81pbu8uvsHojagfxNUPUdCtc
IqNkPktywTUx2PZlNGbiT929WF1RP3ppvpHfSbtLe7rWutONumzIhrzBUUiUURpP
NH8BCG68+5tq9g4dyj4KSMOV5DIn7MNqhdubVVl83UTzRwX26qBnurCby5Jff1kz
Hxulflvq4xCbjc6b20zMcGQCqJrS5QCGiX7lRO3nI2t0ohS+IU+F5q42Yxj/weo0
N2Kq880bpxXY/oYKmk+BnK/niPwhqUlDZeVNajboq29K0rj7W4Sl3IgtcneFA23x
9b5+dqCuxRkoFY9/xWDooZJCyGq9944wFc0s3XYZMOoWGsViyVZ9vMoNu3esSWBn
aglIXq+Zw87vQBlQQVctg9IlHQTRYsdNzb7aWj9Rr+DFLo9Y/r1GLJ1Aifg6d9sR
q07G6h8JwnrjuCrU5EyzuM8YjyG/NXlq32d/gArwSVonWwmviNbIkOEIVfl4OiBO
jaSkdCQwK1WzyaVCDQ6VxZCO0n2V489ptpYFbslcMQleGtLMKfVT27R0Xkfd/CbP
IPqheemnk0bOcOnO4h/BPY6THNogtjf32B5BZWLbj/qRXdIIU70=
=y+hw
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: What's the purpose of this code, that logs a seemingly
meaningless and possibly misleading exception?
Posted by Behrang Saeedzadeh <be...@gmail.com>.
Hi Chris,
I suggested “massaging” it a bit before using the output:
stack trace into a StringWriter via a PrintWriter, massage it a bit
For example:
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Exception e = new Exception();
pw.append("Current stack trace:\n");for (StackTraceElement
stackTraceElement : e.getStackTrace()) {
pw.append("\tat ").append(stackTraceElement.toString()).append("\n");
}
System.out.println(sw.toString());
Which will produce:
Current stack trace:
at com.example.demo.DemoApplication.baz(DemoApplication.java:33)
at com.example.demo.DemoApplication.foo(DemoApplication.java:20)
at com.example.demo.DemoApplication.main(DemoApplication.java:15)
When Tomcat’s minimum required Java runtime version becomes 9 that can be
replaced with StackWalker.
Best regards,
Behrang Saeedzadeh
blog.behrang.org
On Sun, Oct 27, 2019 at 7:48 AM Christopher Schultz <
chris@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Behrang,
>
> On 10/26/19 07:01, Behrang Saeedzadeh wrote:
> > I think so. Another option is to create an exception and print the
> > stack trace into a StringWriter via a PrintWriter, massage it a bit
> > if necessary and add that to the log message.
>
> ... which would produce the same output?
>
> What's the goal of the change?
>
> - -chris
>
> > On Sat, 26 Oct. 2019, 9:12 pm Mark Thomas, <ma...@apache.org>
> > wrote:
> >
> >> On October 25, 2019 9:27:21 AM UTC, Behrang Saeedzadeh <
> >> behrangsa@gmail.com> wrote:
> >>> From Tomcat Embedded Core 9.0.26:
> >>>
> >>> @Override protected void doClose() { if (log.isDebugEnabled())
> >>> { log.debug("Calling [" + getEndpoint() + "].closeSocket([" +
> >>> this + "])", new Exception()); }
> >>>
> >>> Which will log something like:
> >>>
> >>> DEBUG [http-nio-8080-exec-2]
> >>> org.apache.tomcat.util.net.NioEndpoint Calling
> >>> [org.apache.tomcat.util.net.NioEndpoint@654c1a54
> >>
> >>> ].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapp
> er@39e9d240
> >>>
> >>>
> :org.apache.tomcat.util.net.NioChannel@78019ed5
> >> :java.nio.channels.SocketChannel[connected
> >>> local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
> >>>
> >>> java.lang.Exception: null at org.apache.tomcat.util.net
> >> .NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
> >>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
> >>> org.apache.tomcat.util.net
> >> .SocketWrapperBase.close(SocketWrapperBase.java:394)
> >>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
> >>> org.apache.tomcat.util.net
> >> .NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
> >>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
> >>> org.apache.tomcat.util.net
> >> .NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
> >>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
> >>> org.apache.tomcat.util.net
> >> .SocketProcessorBase.run(SocketProcessorBase.java:49)
> >>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
> >>
> >>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor
> .java:1149)
> >>>
> >>>
> [na:1.8.0_212]
> >>> at
> >>
> >>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecuto
> r.java:624)
> >>>
> >>>
> [na:1.8.0_212]
> >>> at
> >>
> >>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskT
> hread.java:61)
> >>>
> >>>
> [tomcat-embed-core-9.0.26.jar:9.0.26]
> >>> at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
> >>>
> >>> To print the stack trace next to the message?
> >>
> >> Yes. So the debug message shows what called close().
> >>
> >>> Every time I turn on debug logging this exception catches me by
> >>> surprise. Why not only print the stack trace next using
> >>> org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace
> >>> for example?
> >>
> >> Because that adds an entire library as a dependency to support a
> >> single debug message. And new Exception() gives what we need
> >> without that dependency. Would adding a message to the exception
> >> such as "Tracing caller" make things clearer?
> >>
> >> Mark
> >>
> >> ---------------------------------------------------------------------
> >>
> >>
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl20sRQACgkQHPApP6U8
> pFjIUhAAnPUFDK1fvi/4LL7hWGThpli/VkHaII3VisokqjjnGLxPAJyzUFy+Gvza
> vjnq1WIYJWQc6r0a8j6FwAvjNVVtJ4WJMP3ANVe154h3RN2Su6q8PMVyZIRE21vY
> kNg3UBcBYsJlAEwd0D7X6jsM2uUIinAmEVLqeNTIJWeo7YpmA1F+txn3Q4BDaO0o
> hQ/i2hfk+d+M6upfmdVV1KW5Me+lwXRdVVMn3cxzxGEUEAXzPanp3tNXVVet4G7Q
> 7erzyxZ0tdxpUl4JbkVHm6mXEykPjsGXNPXLjBbghByI6+M2u1/DQl4maVkRY6g3
> SX/19vfmn60Fgq1XuaKaAepjWTPEUcd6V35U7Pr3f7Dzl6zUG4QsGdCMtQO4YHAJ
> dK3z/CCADudv3xDHqMUJzagB3SUGc86FSYMAslAt6wlYB/5xY9hcF+LApRj5IIEM
> VFN2NEH4g5ehXZMXjULDQzzggW91LUXCD0gHN4b0t1/gcovBVAbcNLbFXCaPIGBj
> Nv7RG546A050ej7ZemUr7dZTshrJHo2OEq16XcxGaeY9e208rXlUlFfyytHFyArv
> ieJI0IN/0iBHOB2nRKdeiB62pdGAU0E2uL64BL6CibCItR/rlhJQsih271z0v3Sd
> M3xdScWJDJ4oKGoxlpdqO65NRC9phTlXnqxWmO4YDPVyqKKHL3E=
> =csbh
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: What's the purpose of this code, that logs a seemingly
meaningless and possibly misleading exception?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Behrang,
On 10/26/19 07:01, Behrang Saeedzadeh wrote:
> I think so. Another option is to create an exception and print the
> stack trace into a StringWriter via a PrintWriter, massage it a bit
> if necessary and add that to the log message.
... which would produce the same output?
What's the goal of the change?
- -chris
> On Sat, 26 Oct. 2019, 9:12 pm Mark Thomas, <ma...@apache.org>
> wrote:
>
>> On October 25, 2019 9:27:21 AM UTC, Behrang Saeedzadeh <
>> behrangsa@gmail.com> wrote:
>>> From Tomcat Embedded Core 9.0.26:
>>>
>>> @Override protected void doClose() { if (log.isDebugEnabled())
>>> { log.debug("Calling [" + getEndpoint() + "].closeSocket([" +
>>> this + "])", new Exception()); }
>>>
>>> Which will log something like:
>>>
>>> DEBUG [http-nio-8080-exec-2]
>>> org.apache.tomcat.util.net.NioEndpoint Calling
>>> [org.apache.tomcat.util.net.NioEndpoint@654c1a54
>>
>>> ].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapp
er@39e9d240
>>>
>>>
:org.apache.tomcat.util.net.NioChannel@78019ed5
>> :java.nio.channels.SocketChannel[connected
>>> local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
>>>
>>> java.lang.Exception: null at org.apache.tomcat.util.net
>> .NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>> org.apache.tomcat.util.net
>> .SocketWrapperBase.close(SocketWrapperBase.java:394)
>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>> org.apache.tomcat.util.net
>> .NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>> org.apache.tomcat.util.net
>> .NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>> org.apache.tomcat.util.net
>> .SocketProcessorBase.run(SocketProcessorBase.java:49)
>>> [tomcat-embed-core-9.0.26.jar:9.0.26] at
>>
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor
.java:1149)
>>>
>>>
[na:1.8.0_212]
>>> at
>>
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecuto
r.java:624)
>>>
>>>
[na:1.8.0_212]
>>> at
>>
>>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskT
hread.java:61)
>>>
>>>
[tomcat-embed-core-9.0.26.jar:9.0.26]
>>> at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
>>>
>>> To print the stack trace next to the message?
>>
>> Yes. So the debug message shows what called close().
>>
>>> Every time I turn on debug logging this exception catches me by
>>> surprise. Why not only print the stack trace next using
>>> org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace
>>> for example?
>>
>> Because that adds an entire library as a dependency to support a
>> single debug message. And new Exception() gives what we need
>> without that dependency. Would adding a message to the exception
>> such as "Tracing caller" make things clearer?
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>>
>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl20sRQACgkQHPApP6U8
pFjIUhAAnPUFDK1fvi/4LL7hWGThpli/VkHaII3VisokqjjnGLxPAJyzUFy+Gvza
vjnq1WIYJWQc6r0a8j6FwAvjNVVtJ4WJMP3ANVe154h3RN2Su6q8PMVyZIRE21vY
kNg3UBcBYsJlAEwd0D7X6jsM2uUIinAmEVLqeNTIJWeo7YpmA1F+txn3Q4BDaO0o
hQ/i2hfk+d+M6upfmdVV1KW5Me+lwXRdVVMn3cxzxGEUEAXzPanp3tNXVVet4G7Q
7erzyxZ0tdxpUl4JbkVHm6mXEykPjsGXNPXLjBbghByI6+M2u1/DQl4maVkRY6g3
SX/19vfmn60Fgq1XuaKaAepjWTPEUcd6V35U7Pr3f7Dzl6zUG4QsGdCMtQO4YHAJ
dK3z/CCADudv3xDHqMUJzagB3SUGc86FSYMAslAt6wlYB/5xY9hcF+LApRj5IIEM
VFN2NEH4g5ehXZMXjULDQzzggW91LUXCD0gHN4b0t1/gcovBVAbcNLbFXCaPIGBj
Nv7RG546A050ej7ZemUr7dZTshrJHo2OEq16XcxGaeY9e208rXlUlFfyytHFyArv
ieJI0IN/0iBHOB2nRKdeiB62pdGAU0E2uL64BL6CibCItR/rlhJQsih271z0v3Sd
M3xdScWJDJ4oKGoxlpdqO65NRC9phTlXnqxWmO4YDPVyqKKHL3E=
=csbh
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: What's the purpose of this code, that logs a seemingly
meaningless and possibly misleading exception?
Posted by Behrang Saeedzadeh <be...@gmail.com>.
I think so. Another option is to create an exception and print the stack
trace into a StringWriter via a PrintWriter, massage it a bit if necessary
and add that to the log message.
On Sat, 26 Oct. 2019, 9:12 pm Mark Thomas, <ma...@apache.org> wrote:
> On October 25, 2019 9:27:21 AM UTC, Behrang Saeedzadeh <
> behrangsa@gmail.com> wrote:
> >From Tomcat Embedded Core 9.0.26:
> >
> >@Override
> >protected void doClose() {
> > if (log.isDebugEnabled()) {
> > log.debug("Calling [" + getEndpoint() + "].closeSocket([" +
> >this + "])", new Exception());
> > }
> >
> >Which will log something like:
> >
> >DEBUG [http-nio-8080-exec-2]
> > org.apache.tomcat.util.net.NioEndpoint
> > Calling [org.apache.tomcat.util.net.NioEndpoint@654c1a54
>
> >].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@39e9d240
> >:org.apache.tomcat.util.net.NioChannel@78019ed5
> :java.nio.channels.SocketChannel[connected
> >local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
> >
> >java.lang.Exception: null
> >at
> >org.apache.tomcat.util.net
> .NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at
> >org.apache.tomcat.util.net
> .SocketWrapperBase.close(SocketWrapperBase.java:394)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at
> >org.apache.tomcat.util.net
> .NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at
> >org.apache.tomcat.util.net
> .NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at
> >org.apache.tomcat.util.net
> .SocketProcessorBase.run(SocketProcessorBase.java:49)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at
>
> >java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
> >[na:1.8.0_212]
> >at
>
> >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
> >[na:1.8.0_212]
> >at
>
> >org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> >[tomcat-embed-core-9.0.26.jar:9.0.26]
> >at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
> >
> >To print the stack trace next to the message?
>
> Yes. So the debug message shows what called close().
>
> > Every time I turn on
> >debug
> >logging this exception catches me by surprise. Why not only print the
> >stack
> >trace next using
> >org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace for
> >example?
>
> Because that adds an entire library as a dependency to support a single
> debug message. And new Exception() gives what we need without that
> dependency. Would adding a message to the exception such as "Tracing
> caller" make things clearer?
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: What's the purpose of this code, that logs a seemingly meaningless and possibly misleading exception?
Posted by Mark Thomas <ma...@apache.org>.
On October 25, 2019 9:27:21 AM UTC, Behrang Saeedzadeh <be...@gmail.com> wrote:
>From Tomcat Embedded Core 9.0.26:
>
>@Override
>protected void doClose() {
> if (log.isDebugEnabled()) {
> log.debug("Calling [" + getEndpoint() + "].closeSocket([" +
>this + "])", new Exception());
> }
>
>Which will log something like:
>
>DEBUG [http-nio-8080-exec-2]
> org.apache.tomcat.util.net.NioEndpoint
> Calling [org.apache.tomcat.util.net.NioEndpoint@654c1a54
>].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@39e9d240
>:org.apache.tomcat.util.net.NioChannel@78019ed5:java.nio.channels.SocketChannel[connected
>local=/127.0.0.1:8080 remote=/127.0.0.1:39988]])
>
>java.lang.Exception: null
>at
>org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doClose(NioEndpoint.java:1165)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at
>org.apache.tomcat.util.net.SocketWrapperBase.close(SocketWrapperBase.java:394)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at
>org.apache.tomcat.util.net.NioEndpoint$Poller.cancelledKey(NioEndpoint.java:667)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at
>org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at
>org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at
>java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>[na:1.8.0_212]
>at
>java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>[na:1.8.0_212]
>at
>org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>[tomcat-embed-core-9.0.26.jar:9.0.26]
>at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
>
>To print the stack trace next to the message?
Yes. So the debug message shows what called close().
> Every time I turn on
>debug
>logging this exception catches me by surprise. Why not only print the
>stack
>trace next using
>org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace for
>example?
Because that adds an entire library as a dependency to support a single debug message. And new Exception() gives what we need without that dependency. Would adding a message to the exception such as "Tracing caller" make things clearer?
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org