I have a small java program which asks the user to input two dates. I want to package this whole program into a jar file. when I try to execute the jar file via command line and redirecting the output to a log file( like this: java -jar Sample.jar >> Sample.log
), all the System.out.println
statements and log statements are printed to the external file, not on console. I want to see the System.out.println
statements printed on the console and log4j log statements in the external file even if the user redirects the output to log file. Please note that I have set the log4j appender to 'Console'. Any idea on how to do that?
The sample program is below:
public class Sample {
public static void main(String[] arg) {
logger.debug("start of the main method");
Scanner in = new Scanner(System.in);
System.out.println("Please enter start date in the format YYYY-MM-DD");
String startDate = in.nextLine();
logger.debug("The entered start date is " + startDate);
System.out.println("Please enter end date in the format YYYY-MM-DD");
logger.debug("The entered end date is " + endDate);
}
}