문제

How to print Stack traces into log file, COM interface is calling our jar file, so need to know the stack trace for debugging.

도움이 되었습니까?

해결책

You can use commons-logging and have code like:

private static final Log LOG_OBJ=LogFactory.getLog(YourClassName.class);

and then:

try {
    //Your implementation here
} catch(Exception e) {
     LOG_OBJ.error("Exception occurred", e);
}

다른 팁

What you can do is wrap system error stream and system output stream and redirect it to some file at startup of your application something like this:

 File logFile = new File("MyLog.log");

 PrintStream ps = new PrintStream(new FileOutputStream(logFile));

 System.setOut(ps);
 System.setErr(ps);

This will redirect all your System.out.print and printStackTraces to log file MyLog.log

Or you can implement some logging mechanism using log4j or java logging.

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top