commits@javamail.java.net

[javamail~mercurial:689] Forgot to include previous change.

From: <shannon_at_java.net>
Date: Tue, 17 Feb 2015 23:00:22 +0000

Project: javamail
Repository: mercurial
Revision: 689
Author: shannon
Date: 2015-02-17 22:59:44 UTC
Link:

Log Message:
------------
Include javadoc example formats for logging - bug 6644

CompactFormatterTest - Fix unused return value warning.

(From Jason)
Forgot to include previous change.


Revisions:
----------
688
689


Modified Paths:
---------------
mail/src/main/java/com/sun/mail/util/logging/CollectorFormatter.java
mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java
mail/src/main/java/com/sun/mail/util/logging/SeverityComparator.java
mail/src/test/java/com/sun/mail/util/logging/CollectorFormatterTest.java
mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java
doc/release/CHANGES.txt


Diffs:
------
diff -r b02d119e7836 -r a3d267f4fdd8 mail/src/main/java/com/sun/mail/util/logging/CollectorFormatter.java
--- a/mail/src/main/java/com/sun/mail/util/logging/CollectorFormatter.java Fri Feb 13 15:10:08 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/CollectorFormatter.java Tue Feb 17 14:48:25 2015 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2015 Jason Mehrens. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -73,7 +73,8 @@
  * {_at_linkplain java.text.MessageFormat MessageFormat} string used to format the
  * collected summary statistics. The arguments are explained in detail in the
  * {_at_linkplain #getTail(java.util.logging.Handler) getTail} documentation.
- * (defaults to "{0}{1}{2}{4,choice,-1#|0#|0&lt;... {4,number,integer} more}\n")
+ * (defaults to <tt>{0}{1}{2}{4,choice,-1#|0#|0&lt;... {4,number,integer}
+ * more}\n</tt>)
  *
  * <li>&lt;formatter-name&gt;.formatter name of a <tt>Formatter</tt> class used
  * to format the collected LogRecord. (defaults to {_at_link CompactFormatter})
@@ -233,22 +234,47 @@
      * <li>{_at_code remaining} the count minus one.
      * <li>{_at_code thrown} the total number of log records
      * {_at_linkplain #format consumed} by this formatter with an assigned
- * throwable.
+ * {_at_linkplain java.util.logging.LogRecord#getThrown throwable}.
      * <li>{_at_code normal messages} the count minus the thrown.
- * <li>{_at_code minMillis} the eldest log record event time
- * {_at_linkplain #format consumed} by this formatter. If no records were
- * formatted then this is set to the approximate start time of the JVM. By
+ * <li>{_at_code minMillis} the eldest log record
+ * {_at_linkplain java.util.logging.LogRecord#getMillis event time}
+ * {_at_linkplain #format consumed} by this formatter. If the count is zero
+ * then this is set to the approximate start time of the JVM. By
      * default this parameter is defined as a number. The format type and format
      * style rules from the {_at_link java.text.MessageFormat} should be used to
- * convert this to a date or time.
- * <li>{_at_code maxMillis} the most recent log record event time
- * {_at_linkplain #format consumed} by this formatter. If no records were
- * formatted then this is set to the current time. By default this parameter
- * is defined as a number. The format type and format style rules from the
- * {_at_link java.text.MessageFormat} should be used to convert this to a date
- * or time.
+ * convert this from milliseconds to a date or time.
+ * <li>{_at_code maxMillis} the most recent log record
+ * {_at_linkplain java.util.logging.LogRecord#getMillis event time}
+ * {_at_linkplain #format consumed} by this formatter. If the count is zero
+ * then this is set to the {_at_link System#currentTimeMillis() current time}.
+ * By default this parameter is defined as a number. The format type and
+ * format style rules from the {_at_link java.text.MessageFormat} should be
+ * used to convert this from milliseconds to a date or time.
      * </ol>
      *
+ * <p>
+ * Some example formats:<br>
+ * <ul>
+ * <li>{_at_code com.sun.mail.util.logging.CollectorFormatter.format={0}{1}{2}{4,choice,-1#|0#|0<... {4,number,integer} more}\n}
+ * <p>
+ * This prints the head ({_at_code {0}}), format ({_at_code {1}}), and tail
+ * ({_at_code {2}}) from the target formatter followed by the number of
+ * remaining ({_at_code {4}}) log records consumed by this formatter if there
+ * are any remaining records.
+ * <pre>
+ * Encoding failed.|NullPointerException: null String.getBytes(:913)... 3 more
+ * </pre>
+ * <li>{_at_code com.sun.mail.util.logging.CollectorFormatter.format=These {3} messages occurred between\n{7,date,EEE, MMM dd HH:mm:ss:S ZZZ yyyy} and {8,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy}\n}
+ * <p>
+ * This prints the count ({_at_code {3}}) followed by the date and time of the
+ * eldest log record ({_at_code {7}}) and the date and time of the most recent
+ * log record ({_at_code {8}}).
+ * <pre>
+ * These 292 messages occurred between
+ * Tue, Jul 21 14:11:42:449 -0500 2009 and Fri, Nov 20 07:29:24:0 -0600 2009
+ * </pre>
+ * </ul>
+ *
      * @param h the handler or null.
      * @return the output string.
      */

diff -r b02d119e7836 -r a3d267f4fdd8 mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java
--- a/mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java Fri Feb 13 15:10:08 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/CompactFormatter.java Tue Feb 17 14:48:25 2015 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2015 Jason Mehrens. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -57,7 +57,7 @@
  * <ul>
  * <li>&lt;formatter-name&gt;.format - the {_at_link java.util.Formatter
  * format} string used to transform the output. The format string can be used to
- * fix the output size. (defaults to "%7$#.160s%n")</li>
+ * fix the output size. (defaults to <tt>%7$#.160s%n</tt>)</li>
  * </ul>
  *
  * @author Jason Mehrens
@@ -121,7 +121,30 @@
      * {_at_link #toAlternate(java.lang.String) alternate} form.</li>
      * </ol>
      *
- * @param record to format.
+ * <p>
+ * Some example formats:<br>
+ * <ul>
+ * <li>{_at_code com.sun.mail.util.logging.CompactFormatter.format=%7$#.160s%n}
+ * <p>
+ * This prints only 160 characters of the message|thrown ({_at_code 7$}) using
+ * the alternate form.
+ * <pre>
+ * Encoding failed.|NullPointerException: null String.getBytes(:913)
+ * </pre>
+ *
+ * <li>{_at_code com.sun.mail.util.logging.CompactFormatter.format=%1$tc %2$s%n%4$s: %5$s%6$s%n}
+ * <p>
+ * This prints the timestamp ({_at_code 1$}) and the source ({_at_code 2$}) on the
+ * first line. The second line is the log level ({_at_code 4$}), log message
+ * ({_at_code 5$}), and the throwable with a relevant stack trace element
+ * ({_at_code 6$}) if one is available.
+ * <pre>
+ * Fri Nov 20 07:29:24 CST 2009 MyClass fatal
+ * SEVERE: Encoding failed.NullPointerException: null String.getBytes(:913)
+ * </pre>
+ * </ul>
+ *
+ * @param record the log record to format.
      * @return the formatted record.
      * @throws NullPointerException if the given record is null.
      */

diff -r b02d119e7836 -r a3d267f4fdd8 mail/src/main/java/com/sun/mail/util/logging/SeverityComparator.java
--- a/mail/src/main/java/com/sun/mail/util/logging/SeverityComparator.java Fri Feb 13 15:10:08 2015 -0800
+++ b/mail/src/main/java/com/sun/mail/util/logging/SeverityComparator.java Tue Feb 17 14:48:25 2015 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2015 Jason Mehrens. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -150,8 +150,7 @@
 
     /**
      * {_at_link #apply(java.lang.Throwable) Reduces} each throwable chain argument
- * then compare each throwable result. This is method can be overridden to
- * change the behavior of {_at_linkplain #compare(LogRecord, LogRecord)}.
+ * then compare each throwable result.
      *
      * @param tc1 the first throwable chain or null.
      * @param tc2 the second throwable chain or null.
@@ -167,7 +166,8 @@
     /**
      * Compares two throwable objects or null. This method does not
      * {_at_link #apply(java.lang.Throwable) reduce} each argument before
- * comparing.
+ * comparing. This is method can be overridden to change the behavior of
+ * {_at_linkplain #compare(LogRecord, LogRecord)}.
      *
      * @param t1 the first throwable or null.
      * @param t2 the second throwable or null.
@@ -253,11 +253,23 @@
         return cmp;
     }
 
+ /**
+ * Determines if the given object is also a comparator and it imposes the
+ * same ordering as this comparator.
+ *
+ * @param o the reference object with which to compare.
+ * @return true if this object equal to the argument; false otherwise.
+ */
     @Override
     public boolean equals(final Object o) {
         return o == null ? false : o.getClass() == getClass();
     }
 
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return Returns a hash code value for the object.
+ */
     @Override
     public int hashCode() {
         return 31 * getClass().hashCode();

diff -r b02d119e7836 -r a3d267f4fdd8 mail/src/test/java/com/sun/mail/util/logging/CollectorFormatterTest.java
--- a/mail/src/test/java/com/sun/mail/util/logging/CollectorFormatterTest.java Fri Feb 13 15:10:08 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/util/logging/CollectorFormatterTest.java Tue Feb 17 14:48:25 2015 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2015 Jason Mehrens. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -388,6 +388,52 @@
     }
 
     @Test
+ public void testGetTailExample1() {
+ String p = "{0}{1}{2}{4,choice,-1#|0#|0<... {4,number,integer} more}\n";
+ CollectorFormatter cf = new CollectorFormatter(p);
+ LogRecord r = new LogRecord(Level.WARNING, "warning message");
+ cf.format(r);
+
+ r = new LogRecord(Level.SEVERE, "Encoding failed.");
+ RuntimeException npe = new NullPointerException();
+ StackTraceElement frame = new StackTraceElement("java.lang.String",
+ "getBytes", "String.java", 913);
+ npe.setStackTrace(new StackTraceElement[]{frame});
+ r.setThrown(npe);
+ cf.format(r);
+
+ cf.format(new LogRecord(Level.INFO, "info"));
+ cf.format(new LogRecord(Level.INFO, "info"));
+ cf.getTail((Handler) null);
+ }
+
+ @Test
+ public void testGetTailExample2() {
+ String p = "These {3} messages occurred between\n{7,date,EEE, MMM dd HH:mm:ss:S ZZZ yyyy} and {8,time,EEE, MMM dd HH:mm:ss:S ZZZ yyyy}\n";
+ CollectorFormatter cf = new CollectorFormatter(p);
+ LogRecord min = new LogRecord(Level.SEVERE, "");
+ min.setMillis(1248203502449L);
+ cf.format(min);
+
+ int count = 290;
+ for (int i = 0; i < count; ++i) {
+ LogRecord mid = new LogRecord(Level.SEVERE, "");
+ mid.setMillis(min.getMillis());
+ cf.format(mid);
+ }
+
+ LogRecord max = new LogRecord(Level.SEVERE, "");
+ max.setMillis(1258723764000L);
+ cf.format(max);
+ Object[] args = new Object[9];
+ args[3] = count + 2L;
+ args[7] = min.getMillis();
+ args[8] = max.getMillis();
+ assertEquals(MessageFormat.format(p, args), cf.toString());
+ cf.getTail((Handler) null);
+ }
+
+ @Test
     public void testNewDefaultFormatter() {
         String msg = "";
         CollectorFormatter f = new CollectorFormatter();

diff -r b02d119e7836 -r a3d267f4fdd8 mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java
--- a/mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java Fri Feb 13 15:10:08 2015 -0800
+++ b/mail/src/test/java/com/sun/mail/util/logging/CompactFormatterTest.java Tue Feb 17 14:48:25 2015 -0800
@@ -1,8 +1,8 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013-2014 Jason Mehrens. All rights reserved.
+ * Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2015 Jason Mehrens. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -40,10 +40,7 @@
  */
 package com.sun.mail.util.logging;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.LogManager;
@@ -460,6 +457,35 @@
     }
 
     @Test
+ public void testFormatExample1() {
+ String p = "%7$#.160s%n";
+ LogRecord r = new LogRecord(Level.SEVERE, "Encoding failed.");
+ RuntimeException npe = new NullPointerException();
+ StackTraceElement frame = new StackTraceElement("java.lang.String",
+ "getBytes", "String.java", 913);
+ npe.setStackTrace(new StackTraceElement[]{frame});
+ r.setThrown(npe);
+ CompactFormatter cf = new CompactFormatter(p);
+ cf.format(r);
+ }
+
+ @Test
+ public void testFormatExample2() {
+ String p = "%1$tc %2$s%n%4$s: %5$s%6$s%n";
+ LogRecord r = new LogRecord(Level.SEVERE, "Encoding failed.");
+ r.setSourceClassName("MyClass");
+ r.setSourceMethodName("fatal");
+ r.setMillis(1258723764000L);
+ RuntimeException npe = new NullPointerException();
+ StackTraceElement frame = new StackTraceElement("java.lang.String",
+ "getBytes", "String.java", 913);
+ npe.setStackTrace(new StackTraceElement[]{frame});
+ r.setThrown(npe);
+ CompactFormatter cf = new CompactFormatter(p);
+ cf.format(r);
+ }
+
+ @Test
     public void testFormatBackTrace() {
         Exception e = new IOException("Fake I/O");
         e = new Exception(e.toString(), e);
@@ -508,7 +534,7 @@
     @Test
     public void testApply() {
         CompactFormatter cf = new CompactFormatter();
- cf.apply((Throwable) null);
+ assertNull(cf.apply((Throwable) null));
 
         final Throwable t = new Throwable();
         Throwable e = cf.apply(t);


diff -r a3d267f4fdd8 -r 2ab7ca2957c6 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Tue Feb 17 14:48:25 2015 -0800
+++ b/doc/release/CHANGES.txt Tue Feb 17 14:59:44 2015 -0800
@@ -28,6 +28,7 @@
 K 6551 Update logging demos to use the new 1.5.2 features
 K 6552 Use classloader ergonomics in the MailHandler
 K 6638 attachment filenames aren't being encoded by default
+K 6644 Include javadoc example formats for logging.
 K 6657 SharedFileInputStream has problems with 2GB+ files
 K 6667 MimeBodyPart with copied DataHandler doesn't always set encoding
 K 6668 skip unusable Store and Transport classes