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);
}
Frage
How to print Stack traces into log file, COM interface is calling our jar file, so need to know the stack trace for debugging.
Lösung
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);
}
Andere Tipps
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.