I have written a program in java which implements some task. I have handled the exception at many places in the program.
My program will daily executes once in a day. I want to maintain a log file in which I want to write the exception if any with the date and time. (At what date and time it gets arise in the program if the program get runs multiple times in the day.)
What should I do for maintaining the single log file? Also I want to save my file with the name like : Log_2012-04-06_0600PM.
Are you using any logging framework like logback or log4j? They provide everything you need. Logging exception is as simple as:
The framework will add any diagnostic information you want, including timestamp, current thread name, class name, etc.
The requirement of adding timestamp to file name is also easily achievable, check out
RollingFileAppender. It will create new log file based on chosen policy, typically every day/hour or when the file grows too large.