muskad202
asked on
determine calling function, java file, linenumber
is it possible from within my function body, to find the calling function, line number, java file ?
thanks :)
muskad202
thanks :)
muskad202
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually, dumpStack() can work, but you first need to redirect System.out to a stream object that you define, so that you can monitor what is printed there. Generally, your filter could just echo to the console, and when a flag is set, copy the stack dump to a vector for later processing. Something like:
class MyPrintStream extends PrintStream
{
PrintStream copy = null;
PrintStream out;
public MyPrintStream(PrintStream out)
{
this.out = out;
}
//
// use this as a model for as many of the PrintStream methods as you feel need to be filtered.
//
public void write(int b)
{
out.write(b);
if (copy != null)
{
copy.write(b);
}
}
public setCopy(PrintStream copy)
{
this.copy = copy;
}
}
MyPrintStream mps = new MyPrintStream(System.out);
System.setOut(mps);
//
// when it is time to check the call stack
//
ByteArrayOutputStream boas = new ByteArrayOutputStream();
mps.setCopy(new PrintStream(boas));
new Exception().printStrackTra ce();
mps.setCopy(nuill);
class MyPrintStream extends PrintStream
{
PrintStream copy = null;
PrintStream out;
public MyPrintStream(PrintStream out)
{
this.out = out;
}
//
// use this as a model for as many of the PrintStream methods as you feel need to be filtered.
//
public void write(int b)
{
out.write(b);
if (copy != null)
{
copy.write(b);
}
}
public setCopy(PrintStream copy)
{
this.copy = copy;
}
}
MyPrintStream mps = new MyPrintStream(System.out);
System.setOut(mps);
//
// when it is time to check the call stack
//
ByteArrayOutputStream boas = new ByteArrayOutputStream();
mps.setCopy(new PrintStream(boas));
new Exception().printStrackTra
mps.setCopy(nuill);
ASKER
was thinking along similar lines ... but the idea is certainly "innovative" :)
thanks :D
muskad202
thanks :D
muskad202
ASKER
one thing .. how do I revert back to the standard output stream ?
You can revert to the standard output stream with:
System.setOut(mps.out);
System.setOut(mps.out);
ASKER
thanks anywayz :)