- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Is it possible to get the package/class/method/function name as string for logging?
I've been using some simple logging for my application where I manually just add these names myself, so I wondered if it's possible to retrieve them automatically (preferably during compilation)?










Re: Is it possible to get the package/class/method/function nam
You can do something like (new Exception).getStackTrace()(1), which
gets you one of these:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StackTraceElement.html
for the method that called you.
HTH,
David
On Wed, Jan 7, 2009 at 3:09 PM, Trond Olsen wrote:
> I've been using some simple logging for my application where I manually just
> add these names myself, so I wondered if it's possible to retrieve them
> automatically (preferably during compilation)?
>
Re: Is it possible to get the package/class/method/function nam
On Thu, Jan 8, 2009 at 12:13 AM, David Hall <david [dot] lw [dot] hall [at] gmail [dot] com> wrote:
Re: Is it possible to get the package/class/method/function nam
Trond Olsen wrote:
>
> How obvious, hehe. Thank you.
>
> On Thu, Jan 8, 2009 at 12:13 AM, David Hall
> wrote:
>
>> You can do something like (new Exception).getStackTrace()(1), which
>> gets you one of these:
>>
>> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StackTraceElement.html
>>
>> for the method that called you.
>>
>> HTH,
>> David
>>
>> On Wed, Jan 7, 2009 at 3:09 PM, Trond Olsen wrote:
>> > I've been using some simple logging for my application where I manually
>> just
>> > add these names myself, so I wondered if it's possible to retrieve them
>> > automatically (preferably during compilation)?
>> >
>>
>
>
Throwing an exception for this is overkill. Since Java 1.5 you can write
Thread.currentThread().getStackTrace()[1]
Re: Is it possible to get the package/class/method/function nam
Note that nobody was throwing an exception.
2009/1/8 Landei <Daniel [dot] Gronau [at] gmx [dot] de>
Re: Is it possible to get the package/class/method/function nam
On Thu, Jan 8, 2009 at 4:07 PM, Ricky Clarkson <ricky [dot] clarkson [at] gmail [dot] com> wrote:
I saw Tony throwing one.
--
Viktor Klang
Senior Systems Analyst