Bookmark Topic Watch Topic
  • New Topic

Parse a complex log file stacktrace  RSS feed

Rithanya Laxmi
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Report post to moderator

I have a complex log file from which I need to retrieve only the stack trace.
Here I am not usng a regex, as the log file is so complex and providing a keyword
for regex itself is tough. Hence I was thinking about the below options:-

1) Write only the log stacktrace in a separate .log file
2) Add a opening and closing tags only for log stacktrace so that it can be easily parsed.

Please provide your suggestion on the same. If i have to implement the first option how i can go about it?
what changes i need to make to log4j xml file? Similarly for the second option how we can do it?
Please clarify.

Anayonkar Shivalkar
Posts: 1558
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Rithanya,

I'm not sure which logging utility you are using - but I hope you are using some logging utility (e.g. java.util.logging, log4j etc.)

Further, I think first option is much better than second option. Even going further what you can do is:

1) Configure a log file via logging utility
2) Configure another file and point your system output stream to that file

Now, all you need to do is - simply printStackTrace and it'll print to the file which is being pointed by system output stream.

This is better than second approach because:
1) No extra coding is required (at least you won't need to code the utility to parse log file)
2) You'll get all stack traces in other file at real time (i.e. no need to wait till file is closed etc.)

I hope this helps.
Richard Tookey
Posts: 1166
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Report post to moderator
In your previous thread on this basic topic you gave very little useful information. This thread contains less information other than the fact that you want to add opening and closing tags. What problems are you having? Are you able to read the log file? Are you now able to parse the log file? Are you stuck on how to add the tags? Are you able to write the new file?
Campbell Ritchie
Posts: 56529
  • Mark post as helpful
  • send pies
  • Report post to moderator
Richard Tookey wrote:In your previous thread . . .
Thank you for noticing; it saves me having to check for duplicate threads.

Rob, Jesper, Anayonkar, I hope I am not treading on your toes by closing this thread.
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!