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); } }

28th Apr 2018, 10:32 PM
Wol B
4 Answers
+ 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.
29th Apr 2018, 12:07 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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
28th Apr 2018, 10:48 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanks, understood
29th Apr 2018, 5:34 PM
Wol B
0
@ChaoticDawg , so in the class I created there IS NOT a method which takes an exception and logs it. True or False
28th Apr 2018, 10:53 PM
Wol B