SummaryFormatter.java revision 670
168N/A/*
670N/A * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
670N/A * Copyright (c) 2009-2014 Jason Mehrens. All Rights Reserved.
168N/A *
168N/A * Redistribution and use in source and binary forms, with or without
168N/A * modification, are permitted provided that the following conditions
168N/A * are met:
168N/A *
168N/A * - Redistributions of source code must retain the above copyright
168N/A * notice, this list of conditions and the following disclaimer.
168N/A *
168N/A * - Redistributions in binary form must reproduce the above copyright
168N/A * notice, this list of conditions and the following disclaimer in the
168N/A * documentation and/or other materials provided with the distribution.
168N/A *
292N/A * - Neither the name of Oracle nor the names of its
168N/A * contributors may be used to endorse or promote products derived
168N/A * from this software without specific prior written permission.
168N/A *
168N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
168N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
168N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
168N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
168N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
168N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
168N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
168N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
168N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
168N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
168N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
168N/A */
168N/A
670N/Aimport com.sun.mail.util.logging.CollectorFormatter;
670N/Aimport com.sun.mail.util.logging.CompactFormatter;
526N/Aimport java.util.logging.Formatter;
526N/Aimport java.util.logging.Handler;
526N/Aimport java.util.logging.LogRecord;
168N/A
168N/A/**
168N/A * A compact formatter used to summarize an error report.
526N/A *
168N/A * @author Jason Mehrens
168N/A */
670N/Apublic final class SummaryFormatter extends Formatter {
168N/A
613N/A /**
670N/A * The line formatter.
613N/A */
670N/A private final CompactFormatter format;
613N/A /**
670N/A * The footer formatter.
613N/A */
670N/A private final CollectorFormatter footer;
168N/A
613N/A /**
613N/A * Creates the formatter.
613N/A */
168N/A public SummaryFormatter() {
670N/A format = new CompactFormatter("[%4$s]\t%5$s %6$s%n");
670N/A footer = new CollectorFormatter("\nThese {3} messages occurred between "
670N/A + "{7,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy} and "
670N/A + "{8,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy}\n", format, null);
168N/A }
168N/A
670N/A /**
670N/A * Gets the header information.
670N/A *
670N/A * @param h the handler or null.
670N/A * @return the header.
670N/A */
526N/A @Override
670N/A public String getHead(Handler h) {
670N/A footer.getHead(h);
670N/A return format.getHead(h);
168N/A }
168N/A
613N/A /**
670N/A * Formats the given record.
670N/A *
670N/A * @param record the log record.
670N/A * @return the formatted record.
670N/A * @throws NullPointerException if record is null.
613N/A */
670N/A public String format(LogRecord record) {
670N/A String data = format.format(record);
670N/A footer.format(record); //Track record times for footer.
670N/A return data;
168N/A }
168N/A
613N/A /**
670N/A * Gets and resets the footer information.
670N/A *
670N/A * @param h the handler or null.
670N/A * @return the footer.
613N/A */
670N/A @Override
670N/A public String getTail(Handler h) {
670N/A format.getTail(h);
670N/A return footer.getTail(h);
168N/A }
168N/A}