I want to write the exceptions that appear in a file. I'm using the mylogger class. The problem is that every time i run the app and an exception is caught the other exceptions are deleted from the file.
here is the mylogger class
public class MyLogger {
static private FileHandler fileTxt;
static private SimpleFormatter formatterTxt;
private Logger logger;
public void setup() throws IOException {
logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
logger.setLevel(Level.INFO);
fileTxt = new FileHandler("Logging.txt");
// create a TXT formatter
formatterTxt = new SimpleFormatter();
fileTxt.setFormatter(formatterTxt);
logger.addHandler(fileTxt);
}
public void log(Exception e) {
logger.info("test");
}
public void logClientReporting(String string) {
// TODO Auto-generated method stub
logger.info(string);
}
public void logSocket(String string) {
// TODO Auto-generated method stub
logger.info(string);
}
}
I call setup in the main class.
Here is how i call the log methods:
catch (Exception e) {
// TODO: handle exception
System.err.println("JSON Exception in getAvailableDesings");
logger.logSocket(e.toString());
}
new FileHandler("Logging.txt", true);? IIRC, the default for append is false, could be wrong, though.