Is there any way to write error log or exception into a file in java. i have gone through Log4j. I googled about it but diidnt find a good solution. I have written a simple code
catch (Exception e) {
PrintWriter pw = new PrintWriter(new FileOutputStream("Log"));
e.printStackTrace(pw);
}
Is there any other way to log the errors or exception? can any body provide me wwith sample example of Log4j?
First read log4j Manual, it’s easy to configure a rolling log file. You do not have to do any explicit file operations.
Second, whenever you catch an exception, do like this
It worth reading the manual. Even better read Complete log4j Manual