public class MyUtil {
public static boolean showLogging;
public static boolean saveLogging;
public static void log(Object s) {
if (showLogging) {
// show logging on console
}
if (saveLogging) {
// save logging to file and append logging old file when it is created
}
}
}
This is my current idea.
I heard of log4j but it’s too complicate for me.
So I just want something that’s simple to print logging on console and also write it to a file based on user configuration.
Use a logging framework, such as the one that comes in the JDK, and configure it to log to both places. They solve these problems for you.
Due to the prevalence of frameworks like log4j, most people standardize on that and use the same logging framework so all things go to the same place. (i.e., they use a third party library which is already using log4j).
Here is something you might want to read to get a handle on how these frameworks work (most are similar):
http://logging.apache.org/log4j/1.2/manual.html
Scroll down a bit in this document to see some real-world examples