Im using websphere server and JSF 2.0
In my managed bean i have declared the following:
private final static Logger LOGGER = Logger.getLogger(ABC.class .getName());
The following code is in the constructor of the bean.
try {
FileHandler handler = new FileHandler("logging.txt");
LOGGER.addHandler(handler);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String stacktrace = sw.toString();
LOGGER.log(Level.SEVERE, stacktrace);
} catch (Exception logException) {
System.err.println("Logging error");
}
The code is writing all the logs to the console but not to the file. The log file logging.txt is also not getting created.
Should I create the file by myself or the path is wrong. Help me
From your code:
That will create a
logging.txtfile in the appserver’s default working directory. You can determine the exact path to the default working directory as follows:The
logging.txtfile should be in that folder.However, this isn’t the best idea. Using relative paths is a bad idea when you cannot control the default working directory from inside your application. You should use absolute paths instead. I.e., start with
/:In Windows, this will be saved in the same disk as where the current working directory is. Otherwise, when you want to change disks as well, you would also need to prefix with
C:or something.Note that this problem is in no way related to JSF. You would have exactly the same problem with any other Java API/framework.