/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.cx.remoting.test.support;

import java.security.AccessController;
import java.security.PrivilegedAction;

import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Handler;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

/**
 *
 */
public final class LoggingHelper {
    private static final class Once {
        static {
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
                public Void run() {
                    final Logger rootLogger = Logger.getLogger("");
                    rootLogger.setLevel(Level.ALL);
                    final Handler[] handlers = rootLogger.getHandlers();
                    for (Handler handler : handlers) {
                        handler.setLevel(Level.ALL);
                        handler.setFormatter(new Formatter() {
                            public String format(final LogRecord record) {
                                StringBuilder builder = new StringBuilder();
                                builder.append(record.getLevel().toString());
                                builder.append(" [").append(record.getLoggerName()).append("] ");
                                builder.append(String.format(record.getMessage(), record.getParameters()));
                                Throwable t = record.getThrown();
                                while (t != null) {
                                    builder.append("\n    Caused by: ");
                                    builder.append(t.getClass().getName());
                                    builder.append(": ");
                                    builder.append(t.getMessage());
                                    for (StackTraceElement e : t.getStackTrace()) {
                                        builder.append("\n        at ");
                                        builder.append(e.getClassName()).append('.').append(e.getMethodName());
                                        builder.append("(").append(e.getFileName()).append(':').append(e.getLineNumber()).append(')');
                                    }
                                    t = t.getCause();
                                }
                                builder.append('\n');
                                return builder.toString();
                            }
                        });
                    }
                    return null;
                }
            });
        }
    }

    private LoggingHelper() {
    }

    public static void init() {
        new Once();
    }
}

@@ -1388,16 +1388,90 @@
  Once %7B%0A
+        private static final long startTime = System.currentTimeMillis();%0A
         
@@ -2100,24 +2100,467 @@
 gBuilder();%0A
+                                long offs = record.getMillis() - startTime;%0A                                final String sign = offs %3C 0 ? %22-%22 : %22+%22;%0A                                offs = Math.abs(offs);%0A                                int ms = (int) (offs %25 1000L);%0A                                long s = offs / 1000L;%0A                                builder.append(String.format(%22%25s%2504d.%2503d %22, sign, Long.valueOf(s), Long.valueOf(ms)));%0A
             

Print relative times in the test log