/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2014 ForgeRock AS. */ package org.forgerock.openidm.patch.utils; import java.io.PrintWriter; import java.io.StringWriter; import java.util.logging.LogRecord; import java.util.logging.SimpleFormatter; /** * JUL log formatter to log messages on a single line. */ public class SingleLineFormatter extends SimpleFormatter { private static final String LINE_FORMAT = "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%6$s%n"; @Override public String format(LogRecord record) { String message = formatMessage(record); String throwable = ""; if (record.getThrown() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println(); record.getThrown().printStackTrace(pw); pw.close(); throwable = sw.toString(); } return String.format(LINE_FORMAT, record.getMillis(), record.getLoggerName(), record.getLoggerName(), record.getLevel().getLocalizedName(), message, throwable); } }