StdOutErrLevel.java

  1. /*
  2.  * StdOutErrLevel
  3.  *
  4.  * $Id: StdOutErrLevel.java 7868 2010-10-21 23:05:34Z jmfee $
  5.  * $URL: https://ehptools.cr.usgs.gov/svn/ProductDistribution/trunk/src/gov/usgs/earthquake/logging/StdOutErrLevel.java $
  6.  */
  7. package gov.usgs.util.logging;

  8. import java.io.InvalidObjectException;
  9. import java.io.ObjectStreamException;
  10. import java.util.logging.Level;

  11. /**
  12.  * Class defining 2 new Logging levels, one for STDOUT, one for STDERR.
  13.  *
  14.  * Used when multiplexing STDOUT and STDERR into the same rolling
  15.  * log file via the Java Logging APIs. From
  16.  * http://blogs.sun.com/nickstephen/entry/java_redirecting_system_out_and
  17.  */
  18. public class StdOutErrLevel extends Level {

  19.     private static final long serialVersionUID = 1L;

  20.     /**
  21.      * Private constructor
  22.      */
  23.     private StdOutErrLevel(String name, int value) {
  24.         super(name, value);
  25.     }

  26.     /**
  27.      * Level for STDOUT activity.
  28.      */
  29.     public static Level STDOUT = new StdOutErrLevel("STDOUT", Level.INFO
  30.             .intValue() + 53);
  31.     /**
  32.      * Level for STDERR activity
  33.      */
  34.     public static Level STDERR = new StdOutErrLevel("STDERR", Level.INFO
  35.             .intValue() + 54);

  36.     /**
  37.      * Method to avoid creating duplicate instances when deserializing the
  38.      * object.
  39.      *
  40.      * @return the singleton instance of this <code>Level</code> value in this
  41.      *         classloader
  42.      * @throws ObjectStreamException
  43.      *             If unable to deserialize
  44.      */
  45.     protected Object readResolve() throws ObjectStreamException {
  46.         if (this.intValue() == STDOUT.intValue())
  47.             return STDOUT;
  48.         if (this.intValue() == STDERR.intValue())
  49.             return STDERR;
  50.         throw new InvalidObjectException("Unknown instance :" + this);
  51.     }

  52. }