Mittwoch, 23. September 2009
Today I had the problem that no stacktrace was printed in logs produced by log4j. Here's an important difference between the logging functions with 1 and 2 parameters:

Logger logger = Logger.getLogger(MyClass.class);
try {
  someFunction();
} catch(MyException e) {
  logger.error("someFunction failed", e); //   prints stacktrace
  logger.error("someFunction failed" + e); // one-liner with type of exception
}

So, use 2 parameters with the Throwable object as 2nd parameter to get a full backtrace. If you want to receive a single line in your output can pass the Throwable as the 1st parameter.




Samstag, 20. Juni 2009
Don't try to achieve this with str.getChars, I never got this working in sth like 2 hours of work. Instead, go for using InputStreamReader if possible. This class includes the required conversion logic.

If 'is' is a InputStream that you want to process, use code like this:

new InputStreamReader(is, "ISO-8859-1");