0
Java logging question, in the class below - is there a method which takes an exception and logs it? If so where, please explain
package supercars.logging; import java.io.PrintStream; public class Logger { private static PrintStream outputLocation = System.err; public static void setOutputLocation(PrintStream ps) { outputLocation = ps; } public static void log(Exception e) { e.printStackTrace(outputLocation); } public static void log(String s, LogLevel level) { outputLocation.println(s); } }
4 Respuestas
+ 2
There IS a method that logs the complete stack trace of the error passed to the log method. By default the error is logged to System.err, which in turn, by default logs the stack trace to the console just as System.out would. You can redirect System.err to a file however, if that is what you're trying to do.
+ 1
Just run your logging method within your catch block.
try {
//code here
} catch(Exception e) {
//call log method here
}
edit: sorry misread the question
Yes, the log(Exception e) method
+ 1
thanks, understood
0
@ChaoticDawg , so in the class I created there IS NOT a method which takes an exception and logs it.
True or False