users@glassfish.java.net

Re: thread name in log messages?

From: Bobby Bissett <bbissett_at_gmail.com>
Date: Thu, 6 Sep 2012 07:18:23 -0400

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
>