diff --git a/src/java/com/samskivert/util/AuditLogger.java b/src/java/com/samskivert/util/AuditLogger.java index 226005d7..19ba57e9 100644 --- a/src/java/com/samskivert/util/AuditLogger.java +++ b/src/java/com/samskivert/util/AuditLogger.java @@ -64,12 +64,14 @@ public class AuditLogger } /** - * Writes the supplied message to the log, prefixed by a date and timestamp. A newline will be - * appended to the message. + * Builds a log entry out of the given message and args using + * {@link Logger#format(Object, Object...)}, prefixes it with the current date and time, + * appends a newline to it and writes it to the log. */ - public synchronized void log (String message) + public synchronized void log (String message, Object...args) { // construct the message + message = Logger.format(message, args); StringBuffer buf = new StringBuffer(message.length() + TIMESTAMP_LENGTH); _format.format(new Date(), buf, _fpos); buf.append(message); diff --git a/src/java/com/samskivert/util/Logger.java b/src/java/com/samskivert/util/Logger.java index 46b47d3f..e97ce88b 100644 --- a/src/java/com/samskivert/util/Logger.java +++ b/src/java/com/samskivert/util/Logger.java @@ -39,6 +39,33 @@ package com.samskivert.util; */ public abstract class Logger { + /** + * Formats the given message and array of alternating key value pairs like so: + * + *
message [key=value, key=value, key=value]+ */ + public static String format (Object message, Object... args) + { + StringBuilder buf = new StringBuilder(); + buf.append(message); + if (args != null && args.length > 1) { + buf.append(" ["); + for (int ii = 0, nn = args.length/2; ii < nn; ii++) { + if (ii > 0) { + buf.append(", "); + } + buf.append(args[2*ii]).append("="); + try { + StringUtil.toString(buf, args[2*ii+1]); + } catch (Throwable t) { + buf.append("