users@glassfish.java.net

Re: thread name in log messages?

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Thu, 06 Sep 2012 10:56:11 -0500

Good grief. I totally missed that. Too many irons. :) I can't answer
your real question, unfortunately. Carla spent some time working on
logging. Perhaps she can chime in if she's paying attention. If not,
you might try emailing her directly.

On 09/06/2012 06:18 AM, Bobby Bissett wrote:
> Hi Jason,
>
> How's it going? In my example, I am setting the name of the thread
> that's doing the logging, but it's not the name that's published in
> the log record. I'm guessing the handler set in GF is using a separate
> thread to actually write to the log file, and was wondering why or if
> that's what's going on. Or if there's some other setting I can use so
> that my thread name shows up. Or something....
>
> Cheers,
> Bobby
>
> On Wed, Sep 5, 2012 at 2:46 PM, Jason Lee <jason.d.lee_at_oracle.com> wrote:
>> There is a ctor on Thread that lets you set the name as you create it, or
>> you can call thread.setName() after the fact. If you don't do that, it
>> calculates it. Somehow. Or is your question how it calculates the default?
>> :)
>>
>>
>> On 09/05/2012 10:27 AM, Bobby Bissett wrote:
>>> Hi all,
>>>
>>> Just curious: where does the thread name come from in messages logged
>>> from an EE app? For instance, in GF 3.1.2.2, I have this servlet:
>>>
>>> --- begin ---
>>> public class TestServlet extends HttpServlet {
>>>
>>> protected void doGet(HttpServletRequest req, HttpServletResponse
>>> resp)
>>> throws ServletException, IOException {
>>>
>>> resp.getWriter().println("hi there");
>>>
>>> TestThread t = new TestThread();
>>> t.start();
>>> }
>>>
>>> static class TestThread extends Thread {
>>>
>>> TestThread() {
>>> super("bobby_test_thread");
>>> }
>>>
>>> @Override
>>> public void run() {
>>> Logger.getLogger("testLogger").info("Hi, I am " + getName());
>>> }
>>> }
>>> }
>>> --- end ---
>>>
>>> ...and when accessed the log contains:
>>>
>>>
>>> [#|2012-09-05T09:45:35.156-0400|INFO|glassfish3.1.2|testLogger|_ThreadID=24;_ThreadName=Thread-4;|Hi,
>>> I am bobby_test_thread|#]
>>>
>>> From where does that "Thread-4" name come (and is there any way to
>>> have it list the thread that logged the message)?
>>>
>>> Thanks,
>>> Bobby
>>
>>
>> --
>> Jason Lee
>> Principal Member of Technical Staff
>> GlassFish Team
>>
>> Oracle Corporation
>> Phone +1 405-216-3193
>> Blog http://blogs.steeplesoft.com
>>


-- 
Jason Lee
Principal Member of Technical Staff
GlassFish Team
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com