Hey guys,
Got my logger working as i wanted it to.. basically it just logs to a file using java.utils.logger
anyway now got a problem.
I'm wanting to duplicate the logging output to a JTextArea on my GUI. So I thought of building a wrapper class but to my suprise it didn't work as expected. It kinda half works and I'm wondering if theres a better way:
here's the code so far...
main...
public class Main {
// Logger log = Logger.getLogger (Main.class.toString ());
public static void main (String[] args) {
logWrapper logs = logWrapper.getInstance ();
logs.logThis (Main.class.toString (), "hello world");
tester te=new tester();
}
}
LogWrapper
public class logWrapper {
//Create the one and only logger
static logWrapper instance;
Logger diagnosticLog = Logger.getLogger ("My logger");
/** Creates a new instance of logWrapper */
private logWrapper () {
}
static logWrapper getInstance () {
if(instance == null) {
instance = new logWrapper ();
}
return instance;
}
public void logThis ( String className, String msg) {
diagnosticLog.log(Level.INFO, className + " " + msg );
}
}
tester
public class tester {
logWrapper logs;
/** Creates a new instance of tester */
public tester () {
logs = logWrapper.getInstance ();
logs.logThis (tester.class.toString (), "making an instance");
}
}
I get the following output which is kinda half right half wrong...
08-Dec-2007 20:39:01 codepadv2.logWrapper logThis
INFO: class codepadv2.Main hello world
08-Dec-2007 20:39:01 codepadv2.logWrapper logThis
INFO: class codepadv2.tester making an instance
if you've noticed that the first line and the thrid line contains the same information whilst they are been called from different functions. I kinda need these lines replaced with the actual function name called....
Any Ideas? I've hoped i've explained it as best as possible....