823N/A * Copyright (c) 2009-2016 Oracle and/or its affiliates. All rights reserved. 823N/A * Copyright (c) 2009-2016 Jason Mehrens. All Rights Reserved. 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 * - Redistributions of source code must retain the above copyright 168N/A * notice, this list of conditions and the following disclaimer. 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. 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 * 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. 670N/A * Demo for the different configurations for the MailHandler. If the logging 670N/A * properties file or class is not specified then this demo will apply some 833N/A * default settings to store emails in the user's temp directory. 168N/A * @author Jason Mehrens 613N/A * The logger for this class name. 168N/A * @param args the command line arguments 823N/A * @throws IOException if there is a problem. 823N/A +
"[[-all] | [-body] | [-custom] | [-debug] | [-low] " 823N/A +
"| [-simple] | [-pushlevel] | [-pushfilter] " 823N/A +
"| [-pushnormal] | [-pushonly]] " 670N/A +
"-all\t\t: Execute all demos.\n" 670N/A +
"-body\t\t: An email with all records and only a body.\n" 823N/A +
"-custom\t\t: An email with attachments and dynamic names.\n" 670N/A +
"-debug\t\t: Output basic debug information about the JVM " 670N/A +
"and log configuration.\n" 670N/A +
"-low\t\t: Generates multiple emails due to low capacity." 670N/A +
"-simple\t\t: An email with all records with body and " 670N/A +
"-pushlevel\t: Generates high priority emails when the" 670N/A +
" push level is triggered and normal priority when " 670N/A +
"-pushFilter\t: Generates high priority emails when the " 670N/A +
"push level and the push filter is triggered and normal " 670N/A +
"priority emails when flushed.\n" 670N/A +
"-pushnormal\t: Generates multiple emails when the " 670N/A +
"MemoryHandler push level is triggered. All generated " 670N/A +
"email are sent as normal priority.\n" 670N/A +
"-pushonly\t: Generates multiple emails when the " 670N/A +
"MemoryHandler push level is triggered. Generates high " 670N/A +
"priority emails when the push level is triggered and " 670N/A +
"normal priority when flushed.\n");
670N/A try {
//Waste some time for the custom formatter. 823N/A //Force parse errors. This does have side effects. 670N/A * java.security.debug=access,stack can be used to trace access to the 295N/A * @param prefix a string to prefix the output. 295N/A * @param err any PrintStream or null for System.out. 823N/A +
" is not set as a system property.");
823N/A * Gets the class loader list. 823N/A * @param cl the class loader or null. 823N/A * @return the class loader list. 670N/A * Gets a formatting string describing the given handler. 670N/A * @param prefix the output prefix. 670N/A * @param err the error stream. 670N/A * @param h the handler. 670N/A * @return the formatted string. 670N/A * Example for body only messages. On close the remaining messages are sent. <code> 670N/A * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler 670N/A * com.sun.mail.util.logging.MailHandler.subject=Body only demo 670N/A * Example showing that when the mail handler reaches capacity it will 670N/A * format and send the current records. Capacity is used to roughly limit 670N/A * the size of an outgoing message. On close any remaining messages are 670N/A * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler 670N/A * com.sun.mail.util.logging.MailHandler.subject=Low capacity demo 670N/A * com.sun.mail.util.logging.MailHandler.capacity=5 670N/A * Example for body only messages. On close any remaining messages are sent. <code> 670N/A * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler 670N/A * com.sun.mail.util.logging.MailHandler.subject=Body and attachment demo 670N/A * com.sun.mail.util.logging.MailHandler.attachment.names=data.xml 670N/A * Example setup for priority messages by level. If the push level is 670N/A * triggered the message is high priority. Otherwise, on close any remaining 670N/A * messages are sent. <code> 670N/A * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler 670N/A * com.sun.mail.util.logging.MailHandler.subject=Push level demo 670N/A * com.sun.mail.util.logging.MailHandler.pushLevel=WARNING 769N/A * Example for priority messages by generation rate. If the push filter is 670N/A * triggered the message is high priority. Otherwise, on close any remaining 769N/A * messages are sent. If the capacity is set to the <code> 670N/A * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler 770N/A * com.sun.mail.util.logging.MailHandler.subject=Push filter demo 670N/A * com.sun.mail.util.logging.MailHandler.pushLevel=ALL 769N/A * com.sun.mail.util.logging.MailHandler.pushFilter=com.sun.mail.util.logging.DurationFilter 769N/A * com.sun.mail.util.logging.DurationFilter.records=2 769N/A * com.sun.mail.util.logging.DurationFilter.duration=1 * 60 * 1000 670N/A * Example for circular buffer behavior. The level, push level, and capacity 670N/A * are set the same so that the memory handler push results in a mail 670N/A * handler push. All messages are high priority. On close any remaining 670N/A * records are discarded because they never reach the mail handler. <code> 670N/A * MailHandlerDemo.handlers=java.util.logging.MemoryHandler 670N/A * java.util.logging.MemoryHandler.target=com.sun.mail.util.logging.MailHandler 670N/A * com.sun.mail.util.logging.MailHandler.level=ALL 670N/A * java.util.logging.MemoryHandler.level=ALL 670N/A * java.util.logging.MemoryHandler.push=WARNING 833N/A * com.sun.mail.util.logging.MailHandler.subject=Push only demo 833N/A * com.sun.mail.util.logging.MailHandler.pushLevel=WARNING 670N/A * Holds on to the push only handler. Only declared here to apply fallback 670N/A * Example for circular buffer behavior as normal priority. The push level, 670N/A * and capacity are set the same so that the memory handler push results in 670N/A * a mail handler push. All messages are normal priority. On close any 670N/A * remaining records are discarded because they never reach the mail 670N/A * handler. Use the LogManager config option or extend the MemoryHandler to 168N/A super.
flush();
//make the target send the email. 670N/A * Holds on to the push normal handler. Only declared here to apply fallback 670N/A * Example for various kinds of custom sorting, formatting, and filtering 670N/A * for multiple attachment messages. The subject will contain the most 670N/A * severe record and a count of remaining records. The log records are 670N/A * ordered from most severe to least severe. The body uses a custom 670N/A * formatter that includes a summary by date and time. The attachment use 670N/A * XML and plain text formats. Each attachment has a different set of 670N/A * filtering. The attachment names are generated from either a fixed name or 670N/A * are built using the number and type of the records formatted. On close 670N/A * any remaining messages are sent. Use the LogManager config option or 670N/A * extend the MemoryHandler to emulate this behavior via the 769N/A //Sort records by severity keeping the severe messages at the top. 168N/A //Use subject to provide a hint as to what is in the email. 168N/A //Make the body give a simple summary of what happened. 168N/A //Create 3 attachments. 670N/A //Filter each attachment differently. 670N/A //Creating the attachment name formatters. 670N/A +
"{5,number,integer} errors}.txt"));
168N/A * Sets up the demos that will run. 670N/A * @param l the list of arguments. 823N/A * @return true if debug is on. 613N/A * Close and remove all handlers added to the class logger. 613N/A * Apply some fallback settings if no configuration file was specified. 670N/A * @return true if fallback settings were applied. 613N/A * Common fallback settings for a single handler. 613N/A * @param h the handler. 613N/A * Gets the system temp directory. 613N/A * @return the system temp directory. 613N/A * Gets the configuration file or class name. 613N/A * @return the file name or class name. 833N/A * No objects are allowed. 833N/A * @throws IllegalAccessException always.