How Can I Pipe the Java Console Output to log file

Good day,

Let me know how to pipe the console info to a log file

thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you mean?

java -jar my.jar > /tmp/mylog.log 2>&1

(Or use 'tee' if you want it in the log file and still on the console

roy_sanudeveloperAuthor Commented:
I am not able to capture console errors  to an log file

public class MIDSkipPolicy implements SkipPolicy {

	private static final Log log = LogFactory.getLog(MIDSkipPolicy.class);

	private Integer skipLimit = null;

	public boolean shouldSkip(Throwable throwable, int skipCount)
			throws SkipLimitExceededException {
		StringBuffer stringBuffer = new StringBuffer();
		if (throwable instanceof FlatFileParseException) {
			int linenumber = ((FlatFileParseException) throwable).getLineNumber();
			String input = ((FlatFileParseException) throwable).getInput();
			stringBuffer.append("Parsing exception encountered on line #" + linenumber + "; input = " + input);
		} else {

			stringBuffer.append("Exception thrown causing record to be skipped: ");
		if (getSkipLimit() <= skipCount && getSkipLimit() > 0) {
			SkipLimitExceededException skipLimitExceededException = new SkipLimitExceededException(skipCount, throwable);			
			throw skipLimitExceededException;
		return true;

	public int getSkipLimit() {
		return skipLimit;

	public void setSkipLimit(int skipLimit) {
		this.skipLimit = skipLimit;

Open in new window

roy_sanudeveloperAuthor Commented:
Adding try catch block  but it is not  able the  capture error to log files.........
where is the issue ......... Any right comments are highly appreciable............

try {

} catch (Exception ex) {
		         // Log the stack trace
		         logger.(Level.SEVERE, ex.getMessage(), ex);

Open in new window

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

That looks like the badly-documented java.util.logging. If so, you can specify the location of log files with the file, the location of which itself you can specify as a jvm property
roy_sanudeveloperAuthor Commented:
i have added like this

but am not able to pipe console error  to a log4j... still it is showing in the console...
do not want to see the error in the console, file

log4j.rootLogger=ERROR, CONSOLE, FILE

# Main appender
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# skip logger, skipappender,summaryappender, CONSOLE, File
log4j.appender.skipappender.layout.ConversionPattern=%d %m%n

Open in new window

roy_sanudeveloperAuthor Commented:
removed the

summaryappender, CONSOLE, File

Open in new window

yes i could able to log the record

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
roy_sanudeveloperAuthor Commented:
removed the console it is working fine
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.