Hi, i have a bit of problem with the logging API, which we just added to our program.
Basically i have a TimerTask class which runs every few mins (24/7) uploading files
Problem #1:
I had OutOfMemoryError after it runs over night if the code is like this. I assumed it's because i keep creating new FileAppender for each run.
public void run()
{
try {
Logger.addAppender(new FileAppender("errorLog.log"));
} catch (IOException e1) {
e1.printStackTrace();
}
Logger.setLevel(Level.ERROR);
// DO THE REST OF THE CODE HERE
Logger.shutdown();
}
Problem #2:
public TimerSchedule()
{
try {
Logger.addAppender(new FileAppender("errorLog.log"));
} catch (IOException e1) {
e1.printStackTrace();
}
Logger.setLevel(Level.ERROR);
}
public void run()
{
//DO THE REST OF THE CODE HERE
Logger.shutdown(); --> the new problem
}
So i moved the Logger.addAppender(new FileAppender("errorLog.log")) to the constructor so it wont be recreated every 5 mins, it actually works. I didnt get OutOfMemoryError after running it all night.
But as stated in the code. Logger.shutdown() is now causing the new problem. If didnt invoke the method, the log seemed doubling for every time my program running the task.
1st loop: 1 error
2nd loop: 2 errors
3rd loop: 3 errors
and so on and so on... it keeps doubling
If i invoked Logger.shutdown() at the end of run() it only did the first loop, and thats it, it stop logging.
1st loop: 1 error
2nd loop: stop logging error
Any tips how to do this correctly? Obviously im doing wrong here.
Thank you...