I'm using java.util.logging
in Android because I need to log to other outputs than the system logs. At the moment I'm using a java.util.logging.SimpleFormatter
. When it logs to a file, it formats the date and timestamp using a default locale, which in my case makes it difficult to read (non-European numerals, complicated use case, long story).
In java.util.Formatter
(as opposed to java.util.logging.Formatter
), you can supply a Locale argument to the constructor, so you can specify the ROOT locale if you want:
Formatter formatter = new Formatter(sb, Locale.ROOT);
(In a similar way you can pass a locale argument to String.format()
.) But java.util.logging.Formatter
and its descendants don't seem to have any way to specify the locale used.
I could extend Formatter
or SimpleFormatter
and override format()
or formatMessage()
, but I don't see any hooks in there for formatting just the date/time stamp, so I'd have to rewrite the functionality of formatting the whole LogRecord. That's probably not too bad, but it's a lot less optimal (and more error-prone) than supplying a locale.
My current strategy is to copy-and-modify the code for SimpleFormatter.format(), but of course that cuts the app off from future fixes to that method.
Any other ideas?