}
public String format(LogRecord record)
{
CPStringBuilder buf = new CPStringBuilder(400);
Level level = record.getLevel();
long millis = record.getMillis();
Object[] params = record.getParameters();
ResourceBundle bundle = record.getResourceBundle();
String message;
buf.append("<record>");
buf.append(lineSep);
appendTag(buf, 1, "date", iso8601.format(new Date(millis)));
appendTag(buf, 1, "millis", millis);
appendTag(buf, 1, "sequence", record.getSequenceNumber());
appendTag(buf, 1, "logger", record.getLoggerName());
if (level.isStandardLevel())
appendTag(buf, 1, "level", level.toString());
else
appendTag(buf, 1, "level", level.intValue());
appendTag(buf, 1, "class", record.getSourceClassName());
appendTag(buf, 1, "method", record.getSourceMethodName());
appendTag(buf, 1, "thread", record.getThreadID());
/* The Sun J2SE 1.4 reference implementation does not emit the
* message in localized form. This is in violation of the API
* specification. The GNU Classpath implementation intentionally
* replicates the buggy behavior of the Sun implementation, as
* different log files might be a big nuisance to users.
*/
try
{
record.setResourceBundle(null);
message = formatMessage(record);
}
finally
{
record.setResourceBundle(bundle);
}
appendTag(buf, 1, "message", message);
/* The Sun J2SE 1.4 reference implementation does not
* emit key, catalog and param tags. This is in violation
* of the API specification. The Classpath implementation
* intentionally replicates the buggy behavior of the
* Sun implementation, as different log files might be
* a big nuisance to users.
*
* FIXME: File a bug report with Sun. Insert bug number here.
*
*
* key = record.getMessage();
* if (key == null)
* key = "";
*
* if ((bundle != null) && !key.equals(message))
* {
* appendTag(buf, 1, "key", key);
* appendTag(buf, 1, "catalog", record.getResourceBundleName());
* }
*
* if (params != null)
* {
* for (int i = 0; i < params.length; i++)
* appendTag(buf, 1, "param", params[i].toString());
* }
*/
/* FIXME: We have no way to obtain the stacktrace before free JVMs
* support the corresponding method in java.lang.Throwable. Well,
* it would be possible to parse the output of printStackTrace,
* but this would be pretty kludgy. Instead, we postpose the
* implementation until Throwable has made progress.
*/
Throwable thrown = record.getThrown();
if (thrown != null)
{
buf.append(" <exception>");
buf.append(lineSep);
/* The API specification is not clear about what exactly
* goes into the XML record for a thrown exception: It
* could be the result of getMessage(), getLocalizedMessage(),
* or toString(). Therefore, it was necessary to write a
* Mauve testlet and run it with the Sun J2SE 1.4 reference
* implementation. It turned out that the we need to call
* toString().
*
* FIXME: File a bug report with Sun, asking for clearer
* specs.
*/
appendTag(buf, 2, "message", thrown.toString());
/* FIXME: The Logging DTD specifies:
*
* <!ELEMENT exception (message?, frame+)>
*
* However, java.lang.Throwable.getStackTrace() is
* allowed to return an empty array. So, what frame should
* be emitted for an empty stack trace? We probably
* should file a bug report with Sun, asking for the DTD
* to be changed.
*/
buf.append(" </exception>");
buf.append(lineSep);
}
buf.append("</record>");
buf.append(lineSep);
return buf.toString();
}