Configure all log handlers to use UTF-8 instead of the JVM's default encoding.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2552 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-05-04 23:44:34 +00:00
parent 75727e6daa
commit f9f1d3a567
@@ -20,6 +20,8 @@
package com.samskivert.util;
import java.io.UnsupportedEncodingException;
import java.util.logging.Handler;
import java.util.logging.Level;
/**
@@ -36,6 +38,20 @@ public class JDK14Logger implements Logger.Factory
if (!Boolean.getBoolean("com.samskivert.util.JDK14Logger.noFormatter")) {
OneLineLogFormatter.configureDefaultHandler();
}
boolean reportedUTF8Missing = false;
for (Handler handler : java.util.logging.Logger.getLogger("").getHandlers()) {
try {
handler.setEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// JVMs are required to support UTF-8 so this shouldn't happen, but if it does,
// tell somebody that things are really fucked
if (!reportedUTF8Missing) {
reportedUTF8Missing = true;
System.err.println("Unable to find UTF-8 encoding. " +
"This JVM ain't right: " + e.getMessage());
}
}
}
} catch (SecurityException se) {
// running in sandbox; no custom logging; no problem!
}