Article View: borland.public.jbuilder.java.api
Article #2085Re: File and line number
From: Torsten Welches
Date: Thu, 07 Jun 2001 11:09
Date: Thu, 07 Jun 2001 11:09
28 lines
1931 bytes
1931 bytes
Steve,
getting a "consistently correct" line number is impossible if
your classes were compiled without debug information.
The same applies for JIT or HotSpot VMs.
Having said that, it's hard enough to get the line number anyway
;-) The best I can think of is generating a stack trace and
parse the output.
What I have used for logging purposes was something like that:
Throwable t = new Throwable("Snapshot");
t.printStackTrace(myLogFilePrintWriter);
I use Log4J now and JDK1.4 will contain a "standard" logging
API. Both of them use the stack trace approach.
Torsten
"Steve Holt" <Steve_Holt@PortaSystems.co.uk> wrote:
>I've found out how to the the file (well actually the class name) but still
>don't have a clue how to get the lione number.
>"Steve Holt" <Steve_Holt@PortaSystems.co.uk> wrote in message
>news:3b1f2fee$1_2@dnews...
>> When creating a log file for my application I want to output the file and
>> line number where
>> the logging takes place. How can I do this without hard coding?
Technical Details
Message-ID:
<3b1f60d8$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsReferences:
<3b1f2fee$1_2@dnews> <3b1f3bb7$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,a0235f9f622697c7 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-06-07 04:10:42 PST From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Subject: Re: File and line number Newsgroups: borland.public.jbuilder.java.api X-User-Info: 193.158.55.74 193.158.55.74 References: <3b1f2fee$1_2@dnews> <3b1f3bb7$1_1@dnews> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3b1f60d8$1_1@dnews> Date: 7 Jun 2001 04:09:12 -0700 X-Trace: dnews 991912152 207.105.83.65 (7 Jun 2001 04:09:12 -0700) Lines: 29 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews