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(""); + } + } + buf.append("]"); + } + return buf.toString(); + } + /** * Used to create logger instances. This is only public so that the log factory can be * configured programmatically via {@link Logger#setFactory}. @@ -110,31 +137,6 @@ public abstract class Logger */ public abstract void error (Object message, Object... args); - /** - * Format messages and arguments. For use by logger implementations. - */ - protected 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(""); - } - } - buf.append("]"); - } - return buf.toString(); - } - /** * Extracts the exception from the message and arguments (if there is one). For use by logger * implementations.