LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2004, 09:45 PM   #1
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
a logger and a printStackTrace in Java


Hello:

I have a simple class logger, for applications and keep a log of exceptions:

Code:
import java.io.*;


/** Class that will act as a general logger for the system, intended for debugging and status control
  *
  * @author KingCrimson
  */
public final class Logger
{

		private static PrintWriter file;

		public static synchronized void log(String what)
		{
			try

			{
				file = new PrintWriter(new FileWriter("c:/ccss.log", true));
				file.println(what);
				file.close();
			}
			catch(Exception e)
			{
				System.out.println("Error en archivo");
				e.printStackTrace();
			}
		}// log

}// logger
and I wanna print there all info related to exceptions, but in a catch statement, the Exception e has a method e.printStackTrace() wich is void, can I take that info and pass it as a string so it suits my Logger class and do something like:

Logger.log(e.printStackTrace());

I've been using the e.getMessage() and the e.toString() but it's not quite the same

Please Help! Thanks a lot

Poeta
 
Old 11-24-2004, 11:30 PM   #2
Jose Muņiz
Member
 
Registered: Jul 2003
Location: Mexico City
Distribution: Slackware 9.1, SuSE 9.1
Posts: 248

Rep: Reputation: 32
I'm not sure if it works, but if you do a

StackTraceElements[] array = exception.getStackTrace();

And then you cycle through each element of the array, executing the following instruction in each cycle:

Logger.log(array[i].toString());

I think that should do the job right?
 
Old 11-24-2004, 11:39 PM   #3
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
Hola paisano!!

Si funcionó, muchisimas gracias

Ahora solo tengo que pelearme con el sql jajaja de casualidad no sabrás que significa el SQLState keycode: S1000 ???

poeta
-----------------------------------------

It did work, thanks a lot! now I just have to struggle with this sql thing.... any idea what SQLState keycode: S1000 stands for?
I'm using mySql and org.gjt.mm.mysql.Driver as a driver for Java

Thanks a lot!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
logger program or command? DJOtaku Linux - General 5 05-16-2005 01:22 AM
keystroke logger??? paugros Linux - Security 18 03-24-2005 12:06 PM
Looking for a shell logger CroMagnon Linux - Software 1 09-13-2004 09:40 PM
personalised logger - need some help chrisfirestar Linux - General 1 03-05-2004 01:50 AM
bandwidth usage logger eltongeoff Linux - Software 6 09-09-2003 11:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration